| 1 |
// PR c++/115586 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
// { dg-options "-Wunused-variable -Wunused-but-set-variable -Wunused-parameter -Wshadow" } |
| 4 |
|
| 5 |
struct S { int a, b, c; }; |
| 6 |
|
| 7 |
void |
| 8 |
foo () |
| 9 |
{ |
| 10 |
S s[4] = {}; |
| 11 |
for (auto [_, _, a] : s) // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 12 |
++a; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } |
| 13 |
for (auto _ : s) |
| 14 |
++_.b; |
| 15 |
for (auto [a, _, b] : s) // { dg-warning "structured bindings only available with" "" { target c++14_down } } |
| 16 |
++a; |
| 17 |
for (auto [_, _, a] : s) // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 18 |
int _ = ++a; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } |
| 19 |
for (auto _ : s) |
| 20 |
{ |
| 21 |
int _ = 2; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 22 |
} |
| 23 |
for (auto [a, _, b] : s) // { dg-warning "structured bindings only available with" "" { target c++14_down } } |
| 24 |
int _ = ++b; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 25 |
} |
| 26 |
|
| 27 |
void |
| 28 |
bar () |
| 29 |
{ |
| 30 |
S s[4] = {}; |
| 31 |
auto [_, c, _] = s[0]; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 32 |
++c; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } |
| 33 |
for (auto [a, _, _] : s) // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 34 |
++a; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } |
| 35 |
for (auto _ : s) |
| 36 |
++_.c; |
| 37 |
for (auto [a, b, _] : s) // { dg-warning "structured bindings only available with" "" { target c++14_down } } |
| 38 |
++b; |
| 39 |
for (auto [a, _, _] : s) // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 40 |
{ // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } |
| 41 |
int _ = ++a; |
| 42 |
} |
| 43 |
for (auto _ : s) |
| 44 |
int _ = 5; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 45 |
for (auto [a, b, _] : s) // { dg-warning "structured bindings only available with" "" { target c++14_down } } |
| 46 |
{ |
| 47 |
int _ = a + b; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } } |
| 48 |
} |
| 49 |
} |