On Tue, Aug 26, 2014 at 03:38:43PM -0400, Jason Merrill wrote:
> commit ccf3f3b41516b34d7d564bed1b3f4e3cf270e43a
> Author: Jason Merrill <ja...@redhat.com>
> Date:   Tue Aug 26 13:56:17 2014 -0400
> 
>       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.
> 
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/tls/thread_local10.C
> @@ -0,0 +1,23 @@
> +// 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();
> +}

Note that this has been committed to 4.8 branch too in r216273,
but there this testcase FAILs:
thread_local10.C:11:10: error: ‘thread_local’ does not name a type
   static thread_local int s;
          ^
thread_local10.C: In constructor ‘A< <template-parameter-1-1> >::A()’:
thread_local10.C:13:14: error: ‘s’ was not declared in this scope
   A () { i = s; }
              ^
thread_local10.C: At global scope:
thread_local10.C:17:23: error: ‘thread_local’ does not name a type
 template <typename T> thread_local int A<T>::s = f();
                       ^

The problem is that something adds -ansi -pedantic-errors after the
-std=c++11, but I couldn't figure out what.  Perhaps just use
// { dg-options "" } before dg-add-options?

        Jakub

Reply via email to