public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Pedro Alves <pedro@palves.net>
Cc: David Malcolm <dmalcolm@redhat.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 1/2] Add gcc/make-unique.h
Date: Tue, 12 Jul 2022 16:14:01 +0100	[thread overview]
Message-ID: <CAH6eHdTgzFXAXRaHpq+u8ZJrwf8J1uB0fkGAvNM+J=TB3PwH7A@mail.gmail.com> (raw)
In-Reply-To: <7f2ddb2d-da00-6852-339a-86c7d853087f@palves.net>

On Tue, 12 Jul 2022 at 15:06, Pedro Alves <pedro@palves.net> wrote:
>
> On 2022-07-12 2:45 p.m., Jonathan Wakely wrote:
> > On Tue, 12 Jul 2022 at 14:24, Pedro Alves wrote:
> >>
> >> On 2022-07-12 1:25 a.m., David Malcolm via Gcc-patches wrote:
> >>
> >>> I tried adding it to gcc/system.h, but anything that uses it needs to
> >>> have std::unique_ptr declared, which meant forcibly including <memory>
> >>> from gcc/system.h
> >>
> >> Did you consider making gcc/system.h include gcc/make-unique.h itself
> >> if INCLUDE_MEMORY is defined?  Something like:
> >>
> >>  #ifdef INCLUDE_MEMORY
> >>  # include <memory>
> >> + #include "make-unique.h"
> >>  #endif
> >>
> >> This is because std::make_unique is defined in <memory> in C++14.  This would
> >> mean fewer changes once GCC requires C++14 (or later) and this new header is eliminated.
> >
> > That's a good idea.
> >
> >>> (in the root namespace, rather than std::, which saves a bit more typing).
> >>
> >> It's less typing now, but it will be more churn once GCC requires C++14 (or later), at
> >> which point you'll naturally want to get rid of the custom make_unique.  More churn
> >> since make_unique -> std::make_unique may require re-indentation of arguments, etc.
> >> For that reason, I would suggest instead to put the function (and any other straight
> >> standard library backport) in a 3-letter namespace already, like, gcc::make_unique
> >> or gnu::make_unique.  That way, when the time comes that GCC requires C++14,
> >> the patch to replace gcc::make_unique won't have to worry about reindenting code,
> >> it'll just replace gcc -> std.
> >
> > Or (when the time comes) don't change gcc->std and do:
> >
> > namespace gcc {
> >   using std::make_unique;
> > }
>
> It will seem like a pointless indirection then, IMO.
>
> >
> > or just leave it in the global namespace as in your current patch, and
> > at a later date add a using-declaration to the global namespace:
> >
> > using std::make_unique;
> >
>
> That's not very idiomatic, though.  Let me turn this into a reverse question:
>
> If GCC required C++14 today, would you be doing the above, either importing make_unique
> to the global namespace, or into namespace gcc?   I think it's safe to say that, no,
> nobody would be doing that.

Erm, I might well do exactly that, for either case.

I don't see a problem with 'using std::make_unique;' into the global
namespace in GCC code. It's not a library header being included by
arbitrary code, it's a single application that isn't going to have
conflicts for some other ::make_unique defined in GCC (because the
::make_unique that is being proposed today would be removed once
C++14's std::make_unique can be used).


>  So once GCC requires C++14, why would you want to preserve
> once-backported symbols in a namespace other than std, when you no longer have a reason to?
> It will just be another unnecessary thing that newcomers at that future time will have
> to learn.

I also don't see a problem with importing std::make_unique into
namespace gcc for local use alongside other things in namespace gcc. I
do consider that idiomatic. It says "the make_unique for gcc code is
std::make_unique". It means you only need a 'using namespace gcc;' at
the top of a source file and you get access to everything in namespace
gcc, even if it is something like std::make_unique that was originally
defined in a different namespace.

  reply	other threads:[~2022-07-12 15:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAH6eHdSnGwtScODMveYha1S5WiDo6YsexN_pRqe9n4vq-Pmkig@mail.gmail.com>
2022-07-12  0:25 ` David Malcolm
2022-07-12  0:25   ` [PATCH 2/2] analyzer: use std::unique_ptr for pending_diagnostic/note David Malcolm
2022-07-12  6:48   ` [PATCH 1/2] Add gcc/make-unique.h Jonathan Wakely
2022-07-12  8:13     ` Jonathan Wakely
2022-10-26 20:40     ` [PATCH v3] " David Malcolm
2022-11-02 21:45       ` Jason Merrill
2022-07-12 13:23   ` [PATCH 1/2] " Pedro Alves
2022-07-12 13:45     ` Jonathan Wakely
2022-07-12 14:06       ` Pedro Alves
2022-07-12 15:14         ` Jonathan Wakely [this message]
2022-07-12 16:40           ` Pedro Alves
2022-07-12 18:22             ` Jonathan Wakely
2022-07-12 18:36               ` Pedro Alves
2022-07-12 18:41                 ` Pedro Alves
2022-07-12 18:58                   ` Jonathan Wakely
2022-07-12 18:59                     ` Jonathan Wakely
2022-07-12 18:50                 ` Jonathan Wakely
2022-07-12 18:56                   ` Pedro Alves
2022-07-12 18:36             ` David Malcolm
2022-07-12 18:49               ` Pedro Alves
2022-10-21 16:01 David Malcolm
2022-10-25 23:00 ` David Malcolm

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='CAH6eHdTgzFXAXRaHpq+u8ZJrwf8J1uB0fkGAvNM+J=TB3PwH7A@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@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).