#1132842 GCC 15 claim PTHREAD_ONCE_INIT is not being a constant.

#1132842#5
Date:
2026-04-06 09:48:28 UTC
From:
To:
I discovered this problem while trying to build mongo-c-driver 2.2.3 to
get rsyslog into Debian.  I was able to reproduce it using a simple C
code fragment.  When using debuild and building this fragment of
src/common/src/common-b64.c

  int
  mcommon_b64_pton(char const *src, uint8_t *target, size_t targsize)
  {
     static bson_once_t once = BSON_ONCE_INIT;

     bson_once(&once, bson_b64_initialize_rmap);

it expands to

     static pthread_once_t once =
  # 503 "/home/pere/src/mongo-c-driver-2.2.3/src/common/src/common-b64.c" 3 4
                              (struct __pthread_once) { 0, 0 }
  # 503 "/home/pere/src/mongo-c-driver-2.2.3/src/common/src/common-b64.c"
                                            ;

     do { do { if (!(__builtin_expect(!!(pthread_once((&once), (bson_b64_initialize_rmap)) == 0), 1))) { _bson_assert_failed_on_line("./src/common/src/common-b64.c", (int)(505), __func__, "pthread_once((&once), (bson_b64_initialize_rmap)) == 0"); } } while (0); } while (0);

which cause this error:

  /home/user/mongo-c-driver-2.2.3/src/common/src/common-b64.c: In
    function '_bson_mcommon_b64_pton':
  /home/user/mongo-c-driver-2.2.3/src/common/src/common-b64.c:503:30:
    error: initializer element is not constant [-Werror=pedantic]
    503 |    static bson_once_t once = BSON_ONCE_INIT;
        |                              ^~~~~~~~~~~~~~

According to
<URL: https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/pthread_once.html >
the value of PTHREAD_ONCE_INIT should be constant.  Is it not so on GNU
Hurd?  I fail to understand how { 0, 0} is not constant, but even a
small test program demonstrate the problem:

  % cat x.c
  #include <pthread.h>
  int main(int argc, char *argv[]) {
    static pthread_once_t once = PTHREAD_ONCE_INIT;
    return 0;
  }
  % gcc -Werror -pedantic x.c
  x.c: In function 'main':
  x.c:3:32: error: initializer element is not constant [-Werror=pedantic]
      3 |   static pthread_once_t once = PTHREAD_ONCE_INIT;
        |                                ^~~~~~~~~~~~~~~~~
  cc1: all warnings being treated as errors
  %

This is using gcc 15.2.0 and an update Debian Hurd based on Sid.

#1132842#10
Date:
2026-04-07 23:59:16 UTC
From:
To:
Hello,

Petter Reinholdtsen, le lun. 06 avril 2026 11:48:28 +0200, a ecrit:

It is, but (pthread_once_t){0,0} is a different thing.

And the issue is that while

can work with PTHREAD_ONCE_INIT being defined to {0,0},

once = PTHREAD_ONCE_INIT

cannot work, even without pedantic. So we really have to keep
(pthread_once_t) in PTHREAD_ONCE_INIT for the dynamic initialization
case.

That being said, it's *really* odd that the package builds with
-Werror=pedantic. Each time gcc gets upgraded to a new version, it will
get new build failures... We'd probably to disable that in the Debian
build.

Samuel