aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-03-24 10:12:25 +0100
committerJakub Jelinek <jakub@redhat.com>2022-03-24 10:12:25 +0100
commit72124f487ccb5c8065dd5f7b8fba254600b7e611 (patch)
tree8de82fe3cbd553d06bbcba957c4685e2a51f5a3e /gcc/cp/decl.cc
parent497bde3ab92b2c292f78672db341bbb7cc1bcf1f (diff)
downloadgcc-72124f487ccb5c8065dd5f7b8fba254600b7e611.zip
gcc-72124f487ccb5c8065dd5f7b8fba254600b7e611.tar.gz
gcc-72124f487ccb5c8065dd5f7b8fba254600b7e611.tar.bz2
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.
Diffstat (limited to 'gcc/cp/decl.cc')
-rw-r--r--gcc/cp/decl.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index efef1b7..68741bbf 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -5774,15 +5774,15 @@ start_decl (const cp_declarator *declarator,
&& cxx_dialect < cxx23)
{
bool ok = false;
- if (CP_DECL_THREAD_LOCAL_P (decl))
+ if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
error_at (DECL_SOURCE_LOCATION (decl),
- "%qD declared %<thread_local%> in %qs function only "
+ "%qD defined %<thread_local%> in %qs function only "
"available with %<-std=c++2b%> or %<-std=gnu++2b%>", decl,
DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
? "consteval" : "constexpr");
else if (TREE_STATIC (decl))
error_at (DECL_SOURCE_LOCATION (decl),
- "%qD declared %<static%> in %qs function only available "
+ "%qD defined %<static%> in %qs function only available "
"with %<-std=c++2b%> or %<-std=gnu++2b%>", decl,
DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
? "consteval" : "constexpr");