Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/decomp2.C

raw
1 // P1091R3
2 // { dg-do run { target c++11 } }
3 // { dg-options "" }
4 // { dg-require-effective-target tls }
5 // { dg-add-options tls }
6
7 namespace std {
8 template<typename T> struct tuple_size;
9 template<int, typename> struct tuple_element;
10 }
11
12 struct A {
13 int i;
14 A(int x) : i(x) {}
15 template <int I> int& get() { return i; }
16 };
17 struct B { int a, b, c; };
18
19 template<> struct std::tuple_size<A> { static const int value = 2; };
20 template<int I> struct std::tuple_element<I,A> { using type = int; };
21
22 extern "C" void abort ();
23 B t = { 4, 5, 6 };
24
25 thread_local auto [ d, e, f ] = t; // { dg-warning "structured binding declaration can be 'thread_local' only" "" { target c++17_down } }
26 // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
27 thread_local auto [ g, h ] = A (44); // { dg-warning "structured binding declaration can be 'thread_local' only" "" { target c++17_down } }
28 // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
29
30 int &
31 baz (int x)
32 {
33 switch (x)
34 {
35 case 0: return d;
36 case 1: return e;
37 case 2: return f;
38 case 3: return g;
39 default: return h;
40 }
41 }
42
43 int
44 qux (int x)
45 {
46 thread_local auto [ m, n, o ] = t; // { dg-warning "structured binding declaration can be 'thread_local' only" "" { target c++17_down } }
47 // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
48 thread_local auto [ p, q ] = A (45); // { dg-warning "structured binding declaration can be 'thread_local' only" "" { target c++17_down } }
49 // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
50 switch (x)
51 {
52 case 0: return ++m;
53 case 1: return ++n;
54 case 2: return ++o;
55 case 3: return ++p;
56 default: return ++q;
57 }
58 }
59
60 int
61 main ()
62 {
63 int *a[5];
64 for (int i = 0; i < 5; ++i)
65 a[i] = &baz (i);
66 for (int i = 0; i < 5; ++i)
67 for (int j = i + 1; j < 5; ++j)
68 if (a[i] == a[j] && (j != i + 1 || i != 3))
69 abort ();
70 if (a[1] != a[0] + 1 || a[2] != a[0] + 2 || a[4] != a[3])
71 abort ();
72 int b[] = { 4, 5, 6, 45, 45 + 6 };
73 for (int i = 0; i < 5; ++i)
74 for (int j = 0; j < 3 + i; ++j)
75 if (qux (i) != b[i] + 1 + j)
76 abort ();
77 }