https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110854

            Bug ID: 110854
           Summary: constructor of std::counting_semaphore is not
                    constexpr
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cooky.ykooc922 at gmail dot com
  Target Milestone: ---

from [thread.sema#lib:counting_semaphore,constructor]:
    constexpr explicit counting_semaphore(ptrdiff_t desired);

but this snippet of code won't compile for gcc >= 11.1 with -std=c++20

=========================================
#include <semaphore>

constinit std::binary_semaphore sem {0};

int main() {}
=========================================
with the following error:
<source>:3:33: error: 'constinit' variable 'sem' does not have a constant
initializer
    3 | constinit std::binary_semaphore sem {0};
      |                                 ^~~
<source>:3:39: error: call to non-'constexpr' function
'std::counting_semaphore<__least_max_value>::counting_semaphore(std::ptrdiff_t)
[with long int __least_max_value = 1; std::ptrdiff_t = long int]'
    3 | constinit std::binary_semaphore sem {0};
      |                                       ^
In file included from <source>:1:
/opt/compiler-explorer/gcc-trunk-20230730/include/c++/14.0.0/semaphore:55:16:
note:
'std::counting_semaphore<__least_max_value>::counting_semaphore(std::ptrdiff_t)
[with long int __least_max_value = 1; std::ptrdiff_t = long int]' declared here
   55 |       explicit counting_semaphore(ptrdiff_t __desired) noexcept
      |                ^~~~~~~~~~~~~~~~~~
Compiler returned: 1

Reply via email to