https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104994
Bug ID: 104994 Summary: extern thread_local declaration rejected in constexpr Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hstong at ca dot ibm.com Target Milestone: --- GCC rejects block-scope extern declarations with the `thread_local` keyword in constexpr bodies. The relevant wording (prior to removal by P2242 <https://wg21.link/p2242>) prohibits only definitions. ### SOURCE (<stdin>): constexpr void f() { extern thread_local int x; } ### COMPILER INVOCATION: g++ -fsyntax-only -std=c++20 -xc++ - ### ACTUAL OUTPUT: <stdin>: In function 'constexpr void f()': <stdin>:2:27: error: 'x' declared 'thread_local' in 'constexpr' function only available with '-std=c++2b' or '-std=gnu++2b' ### EXPECTED OUTPUT: Clean compile. ### COMPILER VERSION INFO (g++ -v): Using built-in specs. COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++ COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/12.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head --enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl --enable-checking=release --disable-nls --enable-lto LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32 Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.0.1 20220319 (experimental) (GCC)