From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id D3FE13858C53 for ; Tue, 12 Jul 2022 10:46:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3FE13858C53 Received: by mail-ej1-x629.google.com with SMTP id ez10so13535948ejc.13 for ; Tue, 12 Jul 2022 03:46:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MMF/6GDxD1AOPbwt7aQgb3IR+u44Zihm5g4BDew4pQ0=; b=y6H+p2t1zkhvdMeaiQDRHbW7RaLFGbEeXNj9MtAAGAkpCsdYr0pDIx4xMfKpy8j8bd 4Vvujthkzm71Qi1Hivu58Wc5TwD5pAPcTfSBCc44Fyz+xtuP4yNYwwqwINnhqG3UTEfG jt+HzdJqUfVNIi5xeW07K2doF9thq4YS5ZeRKgh1eoh9H5wuNhfTRA5QLTzIMiuUys/B pf4ROSRSjafkUH+YjQwjNFOBy3lpja1RZ/LZ0H3dFmD/omcKfiUtpb+E20HL6iRa8P64 fmPBB+3Tj8h03QZI7SDeHdQkNSuBiCBp5//L0noiKO8rPX2daB9XUmRbRNIBHyCrLSsU WN2w== X-Gm-Message-State: AJIora8Lzh9OxDtkYwcHPzaMYKqbTedYsEzujxurp7r6PJMPnZuW89k4 EkjTnpXqTQBsnIIo3tj1107zGlxksRiToJ9yP3M= X-Google-Smtp-Source: AGRyM1s/rTI6Rnf4BQnhao+BPi08mWoaLCYGJH0wV6vTwpVwVp0PFKoTm10MJXQIGto2N0BgZxjP6iEYgFdVym1fikg= X-Received: by 2002:a17:907:7627:b0:72a:9098:e4d3 with SMTP id jy7-20020a170907762700b0072a9098e4d3mr23021092ejc.389.1657622761730; Tue, 12 Jul 2022 03:46:01 -0700 (PDT) MIME-Version: 1.0 References: <20220708204651.42624-1-dmalcolm@redhat.com> <6f183e53-02b9-9472-a5cc-9c57c5c0e898@palves.net> <87zgheskap.fsf@oldenburg.str.redhat.com> In-Reply-To: <87zgheskap.fsf@oldenburg.str.redhat.com> From: Jonathan Wakely Date: Tue, 12 Jul 2022 11:45:50 +0100 Message-ID: Subject: Re: [RFC] Using std::unique_ptr and std::make_unique in our code To: Florian Weimer Cc: Pedro Alves , "gcc@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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 10:46:05 -0000 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.