+2014-08-26 Jason Merrill <jason@redhat.com>
+
+ PR c++/58624
+ * pt.c (tsubst_decl) [VAR_DECL]: Copy TLS model.
+ (tsubst_copy_and_build) [VAR_DECL]: Use TLS wrapper.
+ * semantics.c (finish_id_expression): Don't call TLS wrapper in a
+ template.
+
2014-08-25 Jason Merrill <jason@redhat.com>
* pt.c (check_explicit_specialization): Don't complain about
}
SET_DECL_VALUE_EXPR (r, ve);
}
+ if (TREE_STATIC (r) || DECL_EXTERNAL (r))
+ set_decl_tls_model (r, decl_tls_model (t));
}
else if (DECL_SELF_REFERENCE_P (t))
SET_DECL_SELF_REFERENCE_P (r);
case PARM_DECL:
{
tree r = tsubst_copy (t, args, complain, in_decl);
+ if (VAR_P (r)
+ && !processing_template_decl
+ && !cp_unevaluated_operand
+ && (TREE_STATIC (r) || DECL_EXTERNAL (r))
+ && DECL_THREAD_LOCAL_P (r))
+ {
+ if (tree wrap = get_tls_wrapper_fn (r))
+ /* Replace an evaluated use of the thread_local variable with
+ a call to its wrapper. */
+ r = build_cxx_call (wrap, 0, NULL, tf_warning_or_error);
+ }
if (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE)
/* If the original type was a reference, we'll be wrapped in
tree wrap;
if (VAR_P (decl)
&& !cp_unevaluated_operand
+ && !processing_template_decl
&& (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
&& DECL_THREAD_LOCAL_P (decl)
&& (wrap = get_tls_wrapper_fn (decl)))
--- /dev/null
+// PR c++/58624
+
+// { dg-do run { target c++11 } }
+// { dg-add-options tls }
+// { dg-require-effective-target tls_runtime }
+
+int i;
+
+template <typename> struct A
+{
+ static thread_local int s;
+
+ A () { i = s; }
+};
+
+int f() { return 42; }
+template <typename T> thread_local int A<T>::s = f();
+
+int main () {
+ A<void> a;
+ if (i != 42)
+ __builtin_abort();
+}