From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Pedro Alves <pedro@palves.net>, "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: [RFC] Using std::unique_ptr and std::make_unique in our code
Date: Tue, 12 Jul 2022 11:45:50 +0100 [thread overview]
Message-ID: <CAH6eHdQ45eg=P8i1x5zTc2vi_7oHPAnqa5RBHz_EJhZA6Q3Hxw@mail.gmail.com> (raw)
In-Reply-To: <87zgheskap.fsf@oldenburg.str.redhat.com>
On Tue, 12 Jul 2022 at 11:22, Florian Weimer via Gcc <gcc@gcc.gnu.org> wrote:
>
> * Pedro Alves:
>
> > For example, for the type above, we'd have:
> >
> > typedef std::unique_ptr<pending_diagnostic> 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<pending_diagnostic> 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<pending_diagnostic>;
// ...
};
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.
next prev parent reply other threads:[~2022-07-12 10:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-08 20:46 David Malcolm
2022-07-08 21:15 ` Gabriel Ravier
2022-07-08 21:16 ` Jonathan Wakely
2022-07-11 10:56 ` Pedro Alves
2022-07-12 0:32 ` David Malcolm
2022-08-10 1:15 ` James K. Lowden
2022-07-12 10:21 ` Florian Weimer
2022-07-12 10:45 ` Jonathan Wakely [this message]
2022-07-12 11:01 ` Pedro Alves
2022-07-12 11:00 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH6eHdQ45eg=P8i1x5zTc2vi_7oHPAnqa5RBHz_EJhZA6Q3Hxw@mail.gmail.com' \
--to=jwakely.gcc@gmail.com \
--cc=fweimer@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=pedro@palves.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).