commit 210aa8e75e0827163fd3041890404d39d485d23d
Author: Jason Merrill <jason@redhat.com>
Date: Wed Jun 4 13:28:38 2014 -0400
PR c++/61343
* decl.c (check_initializer): Maybe clear
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
@@ -5856,6 +5856,13 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
if (init && init != error_mark_node)
init_code = build2 (INIT_EXPR, type, decl, init);
+ if (init_code)
+ {
+ /* We might have set these in cp_finish_decl. */
+ DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
+ TREE_CONSTANT (decl) = false;
+ }
+
if (init_code && DECL_IN_AGGR_P (decl))
{
static int explained = 0;
new file mode 100644
@@ -0,0 +1,23 @@
+// PR c++/61343
+
+// { dg-do run { target c++11 } }
+// { dg-add-options tls }
+// { dg-require-effective-target tls_runtime }
+
+struct Foo {
+ int value;
+
+ Foo() noexcept {
+ value = 12;
+ }
+};
+
+static thread_local Foo a{};
+
+static __attribute__((noinline)) void UseA() {
+ if (a.value != 12) __builtin_abort();
+}
+
+int main() {
+ UseA();
+}