Debian Codegraph @

gcc/testsuite/g++.dg/tls/thread_local-order2.C

raw
1 // The standard says that a1 should be destroyed before a0 even though
2 // that isn't reverse order of construction. We need to move
3 // __cxa_thread_atexit into glibc to get this right.
4
5 // { dg-do run }
6 // { dg-require-effective-target c++11 }
7 // { dg-add-options tls }
8 // { dg-require-effective-target tls_runtime }
9 // { dg-xfail-run-if "" { { hppa*-*-hpux* *-*-solaris* } || { newlib } } }
10
11 extern "C" void abort();
12 extern "C" int printf (const char *, ...);
13 #define printf(...)
14
15 int c;
16 struct A {
17 int i;
18 A(int i): i(i) { printf ("A(%d)\n", i); ++c; }
19 ~A() { printf("~A(%d)\n", i); if (i != --c) abort(); }
20 };
21
22 thread_local A a1(1);
23 A* ap = &a1;
24 A a0(0);
25
26 int main()
27 {
28 if (c != 2) abort();
29 }