Index: cp/decl.c =================================================================== --- cp/decl.c (revision 267651) +++ cp/decl.c (working copy) @@ -5235,10 +5236,12 @@ start_decl (const cp_declarator *declarator, { bool ok = false; if (CP_DECL_THREAD_LOCAL_P (decl)) - error ("%qD declared % in % function", - decl); + error_at (DECL_SOURCE_LOCATION (decl), + "%qD declared % in % function", + decl); else if (TREE_STATIC (decl)) - error ("%qD declared % in % function", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "%qD declared % in % function", decl); else ok = true; if (!ok) @@ -8253,18 +8256,18 @@ expand_static_init (tree decl, tree init) if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl) && !DECL_FUNCTION_SCOPE_P (decl)) { + location_t dloc = DECL_SOURCE_LOCATION (decl); if (init) - error ("non-local variable %qD declared %<__thread%> " - "needs dynamic initialization", decl); + error_at (dloc, "non-local variable %qD declared %<__thread%> " + "needs dynamic initialization", decl); else - error ("non-local variable %qD declared %<__thread%> " - "has a non-trivial destructor", decl); + error_at (dloc, "non-local variable %qD declared %<__thread%> " + "has a non-trivial destructor", decl); static bool informed; if (!informed) { - inform (DECL_SOURCE_LOCATION (decl), - "C++11 % allows dynamic initialization " - "and destruction"); + inform (dloc, "C++11 % allows dynamic " + "initialization and destruction"); informed = true; } return; Index: testsuite/g++.dg/diagnostic/constexpr1.C =================================================================== --- testsuite/g++.dg/diagnostic/constexpr1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/constexpr1.C (working copy) @@ -0,0 +1,5 @@ +// { dg-do compile { target c++11 } } + +constexpr void foo() { thread_local int i __attribute__((unused)) {}; } // { dg-error "41:.i. declared .thread_local." } + +constexpr void bar() { static int i __attribute__((unused)) {}; } // { dg-error "35:.i. declared .static." } Index: testsuite/g++.dg/diagnostic/thread1.C =================================================================== --- testsuite/g++.dg/diagnostic/thread1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/thread1.C (working copy) @@ -0,0 +1,13 @@ +// { dg-do compile { target c++11 } } + +int foo(); + +__thread int i __attribute__((unused)) = foo(); // { dg-error "14:non-local variable .i. declared .__thread. needs" } + +struct S +{ + constexpr S() {} + ~S(); +}; + +__thread S s __attribute__((unused)); // { dg-error "12:non-local variable .s. declared .__thread. has" }