Debian Codegraph @

gcc/testsuite/g++.dg/cpp26/name-independent-decl10.C

raw
1 // PR c++/115586
2 // { dg-do compile { target c++11 } }
3 // { dg-options "" }
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 ++_; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
13 // { dg-error "reference to '_' is ambiguous" "" { target *-*-* } .-1 }
14 for (auto _ : s)
15 ++_.b;
16 for (auto [a, _, b] : s) // { dg-warning "structured bindings only available with" "" { target c++14_down } }
17 ++_;
18 for (auto [_, _, a] : s) // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
19 { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
20 ++_; // { dg-error "reference to '_' is ambiguous" }
21 }
22 for (auto _ : s)
23 {
24 ++_.b;
25 int _ = 2; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
26 ++_; // { dg-error "reference to '_' is ambiguous" }
27 }
28 for (auto [a, _, b] : s) // { dg-warning "structured bindings only available with" "" { target c++14_down } }
29 {
30 ++_;
31 int _ = ++b; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
32 ++_; // { dg-error "reference to '_' is ambiguous" }
33 }
34 }
35
36 void
37 bar ()
38 {
39 S s[4] = {};
40 auto [_, c, _] = s[0]; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
41 ++_; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
42 // { dg-error "reference to '_' is ambiguous" "" { target *-*-* } .-1 }
43 for (auto [a, _, _] : s) // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
44 ++_; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
45 // { dg-error "reference to '_' is ambiguous" "" { target *-*-* } .-1 }
46 for (auto _ : s)
47 ++_.c;
48 for (auto [a, b, _] : s) // { dg-warning "structured bindings only available with" "" { target c++14_down } }
49 ++_;
50 for (auto [a, _, _] : s) // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
51 { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
52 ++_; // { dg-error "reference to '_' is ambiguous" }
53 ++a;
54 }
55 for (auto _ : s)
56 int _ = 5; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
57 for (auto [a, b, _] : s) // { dg-warning "structured bindings only available with" "" { target c++14_down } }
58 {
59 ++_;
60 int _ = a + b; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
61 ++_; // { dg-error "reference to '_' is ambiguous" }
62 }
63 }