]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/cpp1z/decomp3.C
Wrap option names in gcc internal messages with %< and %>.
[thirdparty/gcc.git] / gcc / testsuite / g++.dg / cpp1z / decomp3.C
1 // { dg-do compile { target c++11 } }
2 // { dg-options "" }
3
4 struct A { int a, b; float c; };
5 A &bar ();
6 struct B { int d; };
7 B baz ();
8
9 void
10 test (A &b, B c)
11 {
12 int && [ d ] = c; // { dg-error "structured binding declaration cannot have type 'int'" }
13 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
14 char & [ e, f, ff ] { b }; // { dg-error "structured binding declaration cannot have type 'char'" }
15 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
16 auto&[g,h,i]=b; // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } }
17 decltype (auto) [ j ] = c; // { dg-error "structured binding declaration cannot have type 'decltype.auto.'" "" { target c++14 } }
18 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
19 // { dg-error "expected primary-expression before 'decltype'" "" { target c++11_down } .-2 }
20 auto & & && & [ m, n, o ] = b; // { dg-error "multiple ref-qualifiers" }
21 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
22 constexpr auto [ p ] = c; // { dg-error "structured binding declaration cannot be 'constexpr'" }
23 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
24 friend auto [ q ] = c; // { dg-error "'friend' used outside of class" }
25 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
26 typedef auto [ r ] = c; // { dg-error "structured binding declaration cannot be 'typedef'" }
27 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
28 inline auto [ s ] = c; // { dg-error "structured binding declaration cannot be 'inline'" }
29 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
30 __restrict auto [ t ] = c; // { dg-error "invalid use of 'restrict'" }
31 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
32 long long auto [ u ] = c; // { dg-error "'long long' specified with 'auto'" }
33 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
34 virtual auto [ v ] = c; // { dg-error "'virtual' outside class declaration" }
35 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
36 explicit auto [ w ] = c; // { dg-error "'explicit' outside class declaration" }
37 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
38 static auto [ x ] = c; // { dg-error "structured binding declaration cannot be 'static'" }
39 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
40 extern auto [ y ] { c }; // { dg-error "structured binding declaration cannot be 'extern'" }
41 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
42 }
43
44 void
45 test2 (auto & [ p ] = bar ()) // { dg-error "'p' was not declared in this scope" }
46 { // { dg-warning "auto" "" { target { ! concepts } } .-1 }
47 }
48
49 int arr[4];
50
51 void
52 test3 (A &b, B c)
53 {
54 auto [ d, e, f ] = arr; // { dg-error "only 3 names provided" }
55 // { dg-message "while 'int .4.' decomposes into 4 elements" "" { target *-*-* } .-1 }
56 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 }
57 auto & [ g, h, i, j, k ] = arr; // { dg-error "5 names provided" }
58 // { dg-message "while 'int .4.' decomposes into 4 elements" "" { target *-*-* } .-1 }
59 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 }
60 auto [ l, m ] = b; // { dg-error "only 2 names provided" }
61 // { dg-message "while 'A' decomposes into 3 elements" "" { target *-*-* } .-1 }
62 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 }
63 auto & [ n, o, p, q ] = b; // { dg-error "4 names provided" }
64 // { dg-message "while 'A' decomposes into 3 elements" "" { target *-*-* } .-1 }
65 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 }
66 auto [] { c }; // { dg-error "empty structured binding declaration" }
67 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 }
68 auto [ r, s ] = c; // { dg-error "2 names provided" }
69 // { dg-message "while 'B' decomposes into 1 element" "" { target *-*-* } .-1 }
70 // { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 }
71 }