[PATCH] stdlib: Do not define once_flag, ONCE_FLAG_INIT for C++

Collin Funk collin.funk1@gmail.com
Mon Nov 10 06:26:48 GMT 2025


Florian Weimer <fweimer@redhat.com> writes:

> The definition of once_flag conflicts with std::once_flag in
> if “using namespace std;” is active.
>
> Updates commit a7ddbf456d97ac8d1aa7afd735e196a1488bd874
> ("Add once_flag, ONCE_FLAG_INIT and call_once to stdlib.h for C23").
>
> Suggested-by: Jonathan Wakely <jwakely@redhat.com>
>
> ---
>  manual/threads.texi | 17 +++++++++++++++--
>  stdlib/stdlib.h     |  4 +++-
>  2 files changed, 18 insertions(+), 3 deletions(-)

Looks good to me.

Reviewed-by: Collin Funk <collin.funk1@gmail.com>

Should we also mention it in NEWS while we are here [1]? Or I can write
one in a separate patch, if you'd prefer.

The libre package logs shows an installed header does [2]:

   typedef pthread_once_t once_flag;

That probably worked for the most part previously since very few people
use threads.h. But since every program uses stdlib.h, I expect more
compiler errors because of it.

Collin

[1] https://inbox.sourceware.org/libc-alpha/CAH6eHdT65txghU9_eF+zWykTt86o__4pwJsA0PC8kkM2aDcs5A@mail.gmail.com/T/#m8d52000d86a275506badd3b5e44b1087b510f1b9
[2] https://github.com/baresip/re/blob/204fc48836906a2b675c97e1f651513b091e47c9/include/re_thread.h#L46


More information about the Libc-alpha mailing list