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. 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.