On Fri, 19 Dec 2025 at 11:09, Tomasz Kaminski <[email protected]> wrote:
>
>
>
> On Fri, Dec 19, 2025 at 11:57 AM Jonathan Wakely <[email protected]> wrote:
>>
>> Adjust the return type to be consistent with how it's declared in
>> <mutex>.
>>
>> libstdc++-v3/ChangeLog:
>>
>>         * src/c++11/mutex.cc [_GLIBCXX_NO_EXTERN_THREAD_LOCAL]
>>         (__get_once_call): Use std::add_lvalue_reference.
>> ---
>>
>> Pushed to trunk.
>>
>>  libstdc++-v3/src/c++11/mutex.cc | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libstdc++-v3/src/c++11/mutex.cc 
>> b/libstdc++-v3/src/c++11/mutex.cc
>> index 82f0afa4cb4e..91968ab47bd5 100644
>> --- a/libstdc++-v3/src/c++11/mutex.cc
>> +++ b/libstdc++-v3/src/c++11/mutex.cc
>> @@ -42,7 +42,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>    __get_once_callable() noexcept
>>    { return __once_callable; }
>>
>> -  __typeof__(void (*)())&
>> +  std::add_lvalue_reference<void (*)()>::type
>
> Why not simply void(*&)()?

Because that's not valid C++ syntax :-)

See https://gcc.gnu.org/pipermail/gcc-patches/2025-December/703147.html
whre I discussed this.

To return a pointer to a function you need to write:

void (*func())();

And to return a reference to a pointer to a function it would be:

void (*&func())();

Add in the noexcept and we get:

void (*&__call_once() noexcept)();

This is horrific. To make it not horrific you either need a typedef
for the return type:

using R = void(*&)();
R __call_once() noexcept;

Or to turn the entire type into a single declarator, which is what the
original __typeof__ trick does, but it can also be done by using a
template:

std::type_identity_t<void(*&)()>
__call_once() noexcept;

Or what I pushed.


>>
>>    __get_once_call() noexcept
>>    { return __once_call; }
>>
>> --
>> 2.52.0
>>

Reply via email to