| 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-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } } |
| 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 |
thread_local auto [ z ] = c; // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } } |
| 43 |
// { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 } |
| 44 |
} |
| 45 |
|
| 46 |
__thread auto [ z2 ] = B (); // { dg-warning "structured binding declaration can be '__thread' only in" "" { target c++17_down } } |
| 47 |
// { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 } |
| 48 |
|
| 49 |
void |
| 50 |
test2 (auto & [ p ] = bar ()) // { dg-error "'p' was not declared in this scope" } |
| 51 |
{ // { dg-warning "auto" "" { target { ! concepts } } .-1 } |
| 52 |
} |
| 53 |
|
| 54 |
int arr[4]; |
| 55 |
|
| 56 |
void |
| 57 |
test3 (A &b, B c) |
| 58 |
{ |
| 59 |
auto [ d, e, f ] = arr; // { dg-error "only 3 names provided" } |
| 60 |
// { dg-message "while 'int .4.' decomposes into 4 elements" "" { target *-*-* } .-1 } |
| 61 |
// { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 } |
| 62 |
auto & [ g, h, i, j, k ] = arr; // { dg-error "5 names provided" } |
| 63 |
// { dg-message "while 'int .4.' decomposes into 4 elements" "" { target *-*-* } .-1 } |
| 64 |
// { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 } |
| 65 |
auto [ l, m ] = b; // { dg-error "only 2 names provided" } |
| 66 |
// { dg-message "while 'A' decomposes into 3 elements" "" { target *-*-* } .-1 } |
| 67 |
// { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 } |
| 68 |
auto & [ n, o, p, q ] = b; // { dg-error "4 names provided" } |
| 69 |
// { dg-message "while 'A' decomposes into 3 elements" "" { target *-*-* } .-1 } |
| 70 |
// { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 } |
| 71 |
auto [] { c }; // { dg-error "empty structured binding declaration" } |
| 72 |
// { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-1 } |
| 73 |
auto [ r, s ] = c; // { dg-error "2 names provided" } |
| 74 |
// { dg-message "while 'B' decomposes into 1 element" "" { target *-*-* } .-1 } |
| 75 |
// { dg-warning "structured bindings only available with '-std=c..17' or '-std=gnu..17'" "" { target c++14_down } .-2 } |
| 76 |
} |