From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by sourceware.org (Postfix) with ESMTPS id 36CF73857817 for ; Tue, 12 Jul 2022 11:01:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 36CF73857817 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f45.google.com with SMTP id b26so10646329wrc.2 for ; Tue, 12 Jul 2022 04:01:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=d/YBRTq90YKXWeMaAgVN681GGggAnlXxYC0IrPd9wl0=; b=Bw8Jw0DolVrqfwYp84198Wzklz+wfvp1vu4lI3E49lwflXF1OdxhE2zGmnpQigZ+TH If+23T+5TyCBkMs2zxwewIHvLxTRNkopDo43cmOHE9WH4oIx+GxZtYgTdAa0tKJUUdRN o64DzgGZA+WxAzu387EMDmRxDSgZO3KnOtBy9liGcjFVJ92wotxMXbWzOhM8UY6U165n oOA/qZg+VWuvrXNKBhTIHPK/r/T+z+X8CN7PIZZ60ntRh10Pv3xVg+7hix03syKIRUuF G5W7MXk2tx9mEopvXaJ/qxXtBSX6FkxhRJqwKcbsDZWoE+r7PmkKv4Kt3rCdOZ4tiG6f Z2yA== X-Gm-Message-State: AJIora9/fQSVtLQY3JlOv3kMb9YlRhj9BFUGkX7+D0UamPeaaPPaDOxN ouFHhc3GDhUf0n3hWM3fpA2kl7Y9I9U= X-Google-Smtp-Source: AGRyM1t9LwnrriOjAMDQRGD9Tp6mJkAY9nnFr50Nk4DrdbYhMYD0BXx/FNzE5hwICjgwtQkBNm23Qw== X-Received: by 2002:a05:6000:100f:b0:21d:779f:fa87 with SMTP id a15-20020a056000100f00b0021d779ffa87mr22273032wrx.291.1657623716595; Tue, 12 Jul 2022 04:01:56 -0700 (PDT) Received: from ?IPv6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id w13-20020adff9cd000000b0021d20461bbbsm7964576wrr.88.2022.07.12.04.01.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Jul 2022 04:01:55 -0700 (PDT) Subject: Re: [RFC] Using std::unique_ptr and std::make_unique in our code To: Jonathan Wakely , Florian Weimer Cc: "gcc@gcc.gnu.org" References: <20220708204651.42624-1-dmalcolm@redhat.com> <6f183e53-02b9-9472-a5cc-9c57c5c0e898@palves.net> <87zgheskap.fsf@oldenburg.str.redhat.com> From: Pedro Alves Message-ID: <070ee19c-34af-92d8-c499-30792e99ce6e@palves.net> Date: Tue, 12 Jul 2022 12:01:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jul 2022 11:01:59 -0000 On 2022-07-12 11:45 a.m., Jonathan Wakely wrote: > On Tue, 12 Jul 2022 at 11:22, Florian Weimer via Gcc wrote: >> >> * Pedro Alves: >> >>> For example, for the type above, we'd have: >>> >>> typedef std::unique_ptr pending_diagnostic_up; >>> >>> and then: >>> >>> - pending_diagnostic *d, >>> + pending_diagnostic_up d, >>> >>> I would suggest GCC have a similar guideline, before people start >>> using foo_ptr, bar_unp, quux_p, whatnot diverging styles. >> >> This doesn't seem to provide much benefit over writing >> >> uP d; >> >> and with that construct, you don't need to worry about the actual >> relationship between pending_diagnostic and pending_diagnostic_up. >> >> I think the GDB situation is different because many of the types do not >> have proper destructors, so std::unique_ptr needs a custom deleter. > > > A fairly common idiom is for the type to define the typedef itself: > > struct pending_diagnostic { > using ptr = std::unique_ptr; > // ... > }; > > Then you use pending_diagnostic::ptr. If you want a custom deleter for > the type, you add it to the typedef. > > Use a more descriptive name like uptr or uniq_ptr instead of "ptr" if > you prefer. > Only works if you can change the type, though. Sometimes you can't, as it comes from a library.