}
if (VAR_P (r)
- && (TREE_STATIC (r) || CP_DECL_THREAD_LOCAL_P (r))
+ && (TREE_STATIC (r)
+ || (CP_DECL_THREAD_LOCAL_P (r) && !DECL_REALLY_EXTERN (r)))
/* Allow __FUNCTION__ etc. */
&& !DECL_ARTIFICIAL (r))
{
if (!ctx->quiet)
{
if (CP_DECL_THREAD_LOCAL_P (r))
- error_at (loc, "control passes through declaration of %qD "
+ error_at (loc, "control passes through definition of %qD "
"with thread storage duration", r);
else
- error_at (loc, "control passes through declaration of %qD "
+ error_at (loc, "control passes through definition of %qD "
"with static storage duration", r);
}
*non_constant_p = true;
tmp = DECL_EXPR_DECL (t);
if (VAR_P (tmp) && !DECL_ARTIFICIAL (tmp))
{
- if (CP_DECL_THREAD_LOCAL_P (tmp))
+ if (CP_DECL_THREAD_LOCAL_P (tmp) && !DECL_REALLY_EXTERN (tmp))
{
if (flags & tf_error)
- error_at (DECL_SOURCE_LOCATION (tmp), "%qD declared "
+ error_at (DECL_SOURCE_LOCATION (tmp), "%qD defined "
"%<thread_local%> in %<constexpr%> context", tmp);
return false;
}
else if (TREE_STATIC (tmp))
{
if (flags & tf_error)
- error_at (DECL_SOURCE_LOCATION (tmp), "%qD declared "
+ error_at (DECL_SOURCE_LOCATION (tmp), "%qD defined "
"%<static%> in %<constexpr%> context", tmp);
return false;
}
&& 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");
{
if (!x)
return 1;
- static int a; // { dg-error "'a' declared 'static' in 'constexpr' function only available with" "" { target c++20_down } }
+ static int a; // { dg-error "'a' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
return ++a; // { dg-error "uninitialized variable 'a' in 'constexpr' function" "" { target c++17_down } .-1 }
}
{
if (!x)
return 1;
- thread_local int a; // { dg-error "'a' declared 'thread_local' in 'constexpr' function only available with" "" { target c++20_down } }
+ thread_local int a; // { dg-error "'a' defined 'thread_local' in 'constexpr' function only available with" "" { target c++20_down } }
return ++a; // { dg-error "uninitialized variable 'a' in 'constexpr' function" "" { target c++17_down } .-1 }
}
{
if (!x)
return 1;
- extern thread_local int a; // { dg-error "'a' declared 'thread_local' in 'constexpr' function only available with" "" { target c++20_down } }
+ extern thread_local int a; // { dg-bogus "'thread_local' in 'constexpr' function only available with" "" { target c++20_down } }
return ++a;
}
{
if (!x)
return 1;
- static int a; // { dg-error "control passes through declaration of 'a' with static storage duration" }
+ static int a; // { dg-error "control passes through definition of 'a' with static storage duration" }
return ++a;
}
{
if (!x)
return 1;
- thread_local int a; // { dg-error "control passes through declaration of 'a' with thread storage duration" }
+ thread_local int a; // { dg-error "control passes through definition of 'a' with thread storage duration" }
return ++a;
}
constexpr int
bar ()
{
- static int a; // { dg-error "'a' declared 'static' in 'constexpr' context" }
+ static int a; // { dg-error "'a' defined 'static' in 'constexpr' context" }
return ++a;
}
constexpr int
baz (int x)
{
- thread_local int a; // { dg-error "'a' declared 'thread_local' in 'constexpr' context" }
+ thread_local int a; // { dg-error "'a' defined 'thread_local' in 'constexpr' context" }
return ++a;
}
--- /dev/null
+// PR c++/104994
+// CWG2552
+// { dg-do compile { target c++14 } }
+
+constexpr bool foo () { extern thread_local int t; return true; }
+static constexpr bool a = foo ();
consteval int
f13 (int x)
{
- static int a = 5; // { dg-error "'a' declared 'static' in 'consteval' function only available with" "" { target c++20_only } }
- // { dg-error "'a' declared 'static' in 'constexpr' context" "" { target c++23 } .-1 }
- thread_local int b = 6; // { dg-error "'b' declared 'thread_local' in 'consteval' function only available with" "" { target c++20_only } }
+ static int a = 5; // { dg-error "'a' defined 'static' in 'consteval' function only available with" "" { target c++20_only } }
+ // { dg-error "'a' defined 'static' in 'constexpr' context" "" { target c++23 } .-1 }
+ thread_local int b = 6; // { dg-error "'b' defined 'thread_local' in 'consteval' function only available with" "" { target c++20_only } }
return x;
}
constexpr int foo ()
try { // { dg-warning "function-try-block body of 'constexpr' function only available with" "" { target c++17_down } }
int a; // { dg-error "uninitialized variable 'a' in 'constexpr' function" "" { target c++17_down } }
- static double b = 1.0;// { dg-error "'b' declared 'static' in 'constexpr' function only available with" "" { target c++20_down } }
- // { dg-error "'b' declared 'static' in 'constexpr' context" "" { target c++23 } .-1 }
+ static double b = 1.0;// { dg-error "'b' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
+ // { dg-error "'b' defined 'static' in 'constexpr' context" "" { target c++23 } .-1 }
goto l; // { dg-error "'goto' in 'constexpr' function only available with" "" { target c++20_down } }
l:;
return 0;
} catch (...) {
long int c; // { dg-error "uninitialized variable 'c' in 'constexpr' function" "" { target c++17_down } }
- static float d = 2.0f;// { dg-error "'d' declared 'static' in 'constexpr' function only available with" "" { target c++20_down } }
+ static float d = 2.0f;// { dg-error "'d' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
goto l2; // { dg-error "'goto' in 'constexpr' function only available with" "" { target c++20_down } }
l2:;
return -1;
constexpr int bar ()
{
int a; // { dg-error "uninitialized variable 'a' in 'constexpr' function" "" { target c++17_down } }
- static long double b = 3.0;// { dg-error "'b' declared 'static' in 'constexpr' function only available with" "" { target c++20_down } }
- // { dg-error "'b' declared 'static' in 'constexpr' context" "" { target c++23 } .-1 }
+ static long double b = 3.0;// { dg-error "'b' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
+ // { dg-error "'b' defined 'static' in 'constexpr' context" "" { target c++23 } .-1 }
goto l; // { dg-error "'goto' in 'constexpr' function only available with" "" { target c++20_down } }
l:;
try { // { dg-warning "'try' in 'constexpr' function only available with" "" { target c++17_down } }
short c; // { dg-error "uninitialized variable 'c' in 'constexpr' function" "" { target c++17_down } }
- static float d; // { dg-error "'d' declared 'static' in 'constexpr' function only available with" "" { target c++20_down } }
+ static float d; // { dg-error "'d' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
// { dg-error "uninitialized variable 'd' in 'constexpr' function" "" { target c++17_down } .-1 }
goto l2; // { dg-error "'goto' in 'constexpr' function only available with" "" { target c++20_down } }
l2:;
return 0;
} catch (int) {
char e; // { dg-error "uninitialized variable 'e' in 'constexpr' function" "" { target c++17_down } }
- static int f = 5; // { dg-error "'f' declared 'static' in 'constexpr' function only available with" "" { target c++20_down } }
+ static int f = 5; // { dg-error "'f' defined 'static' in 'constexpr' function only available with" "" { target c++20_down } }
goto l3; // { dg-error "'goto' in 'constexpr' function only available with" "" { target c++20_down } }
l3:;
return 1;
// { dg-do compile { target c++11 } }
-constexpr int foo() { thread_local int i __attribute__((unused)) {}; return 1; } // { dg-error "40:.i. declared .thread_local." "" { target c++20_down } }
-// { dg-error "40:.i. declared .thread_local. in .constexpr. context" "" { target c++23 } .-1 }
+constexpr int foo() { thread_local int i __attribute__((unused)) {}; return 1; } // { dg-error "40:.i. defined .thread_local." "" { target c++20_down } }
+// { dg-error "40:.i. defined .thread_local. in .constexpr. context" "" { target c++23 } .-1 }
-constexpr int bar() { static int i __attribute__((unused)) {}; return 1; } // { dg-error "34:.i. declared .static." "" { target c++20_down } }
-// { dg-error "34:.i. declared .static. in .constexpr. context" "" { target c++23 } .-1 }
+constexpr int bar() { static int i __attribute__((unused)) {}; return 1; } // { dg-error "34:.i. defined .static." "" { target c++20_down } }
+// { dg-error "34:.i. defined .static. in .constexpr. context" "" { target c++23 } .-1 }