public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104994] New: extern thread_local declaration rejected in constexpr
@ 2022-03-20 22:50 hstong at ca dot ibm.com
  2022-03-21 10:37 ` [Bug c++/104994] " jakub at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: hstong at ca dot ibm.com @ 2022-03-20 22:50 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
@ 2022-03-21 10:37 ` jakub at gcc dot gnu.org
  2022-03-21 10:44 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-03-21 10:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, is
constexpr bool foo() { extern thread_local int x; return true; }
static_assert (foo (), "");
valid C++14/17 and invalid C++20/23 then (the new P2242 wording says
"a control flow that passes through a declaration of a variable with static or
thread storage duration;")?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
  2022-03-21 10:37 ` [Bug c++/104994] " jakub at gcc dot gnu.org
@ 2022-03-21 10:44 ` jakub at gcc dot gnu.org
  2022-03-21 13:56 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-03-21 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Jason, thoughts on this?
It is true that clang++ accepts the #c0 testcase, both clang++ and g++ accept
const thread_local int a = 1;
constexpr int foo () { return a; }
static_assert (foo () == 1, "");

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
  2022-03-21 10:37 ` [Bug c++/104994] " jakub at gcc dot gnu.org
  2022-03-21 10:44 ` jakub at gcc dot gnu.org
@ 2022-03-21 13:56 ` redi at gcc dot gnu.org
  2022-03-21 13:57 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-21 13:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Ville says that P2242 did not intend to add new restrictions, so this was valid
in C++20, and should still be valid in C++23 even if control flow passes over
that non-local declaration. We might have a defect in the current draft,
because it seems to forbid it.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
                   ` (2 preceding siblings ...)
  2022-03-21 13:56 ` redi at gcc dot gnu.org
@ 2022-03-21 13:57 ` redi at gcc dot gnu.org
  2022-03-21 15:26 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-21 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> We might have a defect in the
> current draft, because it seems to forbid it.

Oh, which Hubert already filed:
https://cplusplus.github.io/CWG/issues/2552.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
                   ` (3 preceding siblings ...)
  2022-03-21 13:57 ` redi at gcc dot gnu.org
@ 2022-03-21 15:26 ` jakub at gcc dot gnu.org
  2022-03-24  9:13 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-03-21 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 52657
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52657&action=edit
gcc12-pr104994.patch

Untested fix.  This anticipates that CWG.  If we wouldn't, we should
temporarily revert those changes for the passing through case.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
                   ` (4 preceding siblings ...)
  2022-03-21 15:26 ` jakub at gcc dot gnu.org
@ 2022-03-24  9:13 ` cvs-commit at gcc dot gnu.org
  2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-24  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:72124f487ccb5c8065dd5f7b8fba254600b7e611

commit r12-7793-g72124f487ccb5c8065dd5f7b8fba254600b7e611
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 24 10:12:25 2022 +0100

    c++: extern thread_local declarations in constexpr [PR104994]

    C++14 to C++20 apparently should allow extern thread_local declarations in
    constexpr functions, however useless they are there (because accessing
    such vars is not valid in a constant expression, perhaps sizeof/decltype).
    P2242 changed that for C++23 to passing through declaration but
    https://cplusplus.github.io/CWG/issues/2552.html
    has been filed for it yesterday.

    The following patch implements the proposed wording of CWG 2552 in addition
    to fixing the C++14 - C++20 handling bug.
    If you'd like instead to keep the current pedantic C++23 wording for now,
    that would mean taking out the first hunk (cxx_eval_constant_expression)
and
    g++.dg/cpp23/constexpr-nonlit2.C hunk.

    2022-03-24  Jakub Jelinek  <jakub@redhat.com>

            PR c++/104994
            * constexpr.cc (cxx_eval_constant_expression): Don't diagnose
passing
            through extern thread_local declarations.  Change wording from
            declaration to definition.
            (potential_constant_expression_1): Don't diagnose extern
thread_local
            declarations.  Change wording from declared to defined.
            * decl.cc (start_decl): Likewise.

            * g++.dg/diagnostic/constexpr1.C: Change expected diagnostic
wording
            from declared to defined.
            * g++.dg/cpp23/constexpr-nonlit1.C: Likewise.
            (garply): Change dg-error into dg-bogus.
            * g++.dg/cpp23/constexpr-nonlit2.C: Change expected diagnostic
wording
            from declaration to definition.
            * g++.dg/cpp23/constexpr-nonlit6.C: Change expected diagnostic
wording
            from declared to defined.
            * g++.dg/cpp23/constexpr-nonlit7.C: New test.
            * g++.dg/cpp2a/constexpr-try5.C: Change expected diagnostic wording
            from declared to defined.
            * g++.dg/cpp2a/consteval3.C: Likewise.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
                   ` (5 preceding siblings ...)
  2022-03-24  9:13 ` cvs-commit at gcc dot gnu.org
@ 2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org
  2022-05-10  8:25 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-29  5:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:51b5fa6b4257850c99094f2cf7ece949b00a7826

commit r11-9734-g51b5fa6b4257850c99094f2cf7ece949b00a7826
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 24 10:12:25 2022 +0100

    c++: extern thread_local declarations in constexpr [PR104994]

    C++14 to C++20 apparently should allow extern thread_local declarations in
    constexpr functions, however useless they are there (because accessing
    such vars is not valid in a constant expression, perhaps sizeof/decltype).
    P2242 changed that for C++23 to passing through declaration but
    https://cplusplus.github.io/CWG/issues/2552.html
    has been filed for it yesterday.

    2022-03-24  Jakub Jelinek  <jakub@redhat.com>

            PR c++/104994
            * constexpr.c (potential_constant_expression_1): Don't diagnose
extern
            thread_local declarations.
            * decl.c (start_decl): Likewise.

            * g++.dg/cpp23/constexpr-nonlit7.C: New test.

    (cherry picked from commit 72124f487ccb5c8065dd5f7b8fba254600b7e611)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
                   ` (6 preceding siblings ...)
  2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org
@ 2022-05-10  8:25 ` cvs-commit at gcc dot gnu.org
  2022-05-11  6:25 ` cvs-commit at gcc dot gnu.org
  2022-05-11  6:36 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-10  8:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:125234a3b78138e22112bb3f207df987817b6818

commit r10-10698-g125234a3b78138e22112bb3f207df987817b6818
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 24 10:12:25 2022 +0100

    c++: extern thread_local declarations in constexpr [PR104994]

    C++14 to C++20 apparently should allow extern thread_local declarations in
    constexpr functions, however useless they are there (because accessing
    such vars is not valid in a constant expression, perhaps sizeof/decltype).
    P2242 changed that for C++23 to passing through declaration but
    https://cplusplus.github.io/CWG/issues/2552.html
    has been filed for it yesterday.

    2022-03-24  Jakub Jelinek  <jakub@redhat.com>

            PR c++/104994
            * constexpr.c (potential_constant_expression_1): Don't diagnose
extern
            thread_local declarations.
            * decl.c (start_decl): Likewise.

            * g++.dg/cpp2a/constexpr-nonlit7.C: New test.

    (cherry picked from commit 72124f487ccb5c8065dd5f7b8fba254600b7e611)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
                   ` (7 preceding siblings ...)
  2022-05-10  8:25 ` cvs-commit at gcc dot gnu.org
@ 2022-05-11  6:25 ` cvs-commit at gcc dot gnu.org
  2022-05-11  6:36 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-11  6:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:54bccc8e05f6f9480b50c4edfb2a364d344e72c0

commit r9-10141-g54bccc8e05f6f9480b50c4edfb2a364d344e72c0
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 24 10:12:25 2022 +0100

    c++: extern thread_local declarations in constexpr [PR104994]

    C++14 to C++20 apparently should allow extern thread_local declarations in
    constexpr functions, however useless they are there (because accessing
    such vars is not valid in a constant expression, perhaps sizeof/decltype).
    P2242 changed that for C++23 to passing through declaration but
    https://cplusplus.github.io/CWG/issues/2552.html
    has been filed for it yesterday.

    2022-03-24  Jakub Jelinek  <jakub@redhat.com>

            PR c++/104994
            * constexpr.c (potential_constant_expression_1): Don't diagnose
extern
            thread_local declarations.
            * decl.c (start_decl): Likewise.

            * g++.dg/cpp2a/constexpr-nonlit7.C: New test.

    (cherry picked from commit 72124f487ccb5c8065dd5f7b8fba254600b7e611)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/104994] extern thread_local declaration rejected in constexpr
  2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
                   ` (8 preceding siblings ...)
  2022-05-11  6:25 ` cvs-commit at gcc dot gnu.org
@ 2022-05-11  6:36 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-11  6:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-05-11  6:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-20 22:50 [Bug c++/104994] New: extern thread_local declaration rejected in constexpr hstong at ca dot ibm.com
2022-03-21 10:37 ` [Bug c++/104994] " jakub at gcc dot gnu.org
2022-03-21 10:44 ` jakub at gcc dot gnu.org
2022-03-21 13:56 ` redi at gcc dot gnu.org
2022-03-21 13:57 ` redi at gcc dot gnu.org
2022-03-21 15:26 ` jakub at gcc dot gnu.org
2022-03-24  9:13 ` cvs-commit at gcc dot gnu.org
2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org
2022-05-10  8:25 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:25 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:36 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).