Debian Codegraph @

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

raw
1 // P2169R4 - A nice placeholder with no name
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wunused-variable -Wunused-but-set-variable -Wunused-parameter -Wshadow" }
4
5 int a[3];
6
7 void
8 foo ()
9 {
10 {
11 int _ = 1;
12 ++_;
13 }
14 {
15 int _ = 3;
16 ++_;
17 int _ = 4; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
18 }
19 {
20 int _ = 5;
21 --_;
22 int _ = 6; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
23 int _ = 7; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
24 }
25 {
26 auto [i, j, _] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
27 ++i;
28 ++_;
29 }
30 {
31 auto [_, _, k] = a; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
32 ++k; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
33 }
34 {
35 auto [i, j, _] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
36 auto [_, k, l] = a; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
37 ++i; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 }
38 ++l;
39 }
40 {
41 int _;
42 _ = 1;
43 }
44 {
45 int _ = 1;
46 }
47 {
48 int _;
49 }
50 {
51 static int _; // { dg-warning "unused variable" }
52 int _ = 1; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
53 }
54 {
55 extern int _ (int);
56 extern long _ (long);
57 extern float _ (float);
58 int _ = 1; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
59 }
60 {
61 extern double _ (double);
62 extern short _ (short);
63 int _ = 1; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
64 int _ = 2; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
65 }
66 {
67 int _ = 1;
68 {
69 int _ = 2;
70 ++_;
71 }
72 {
73 static int _ = 3;
74 ++_;
75 }
76 {
77 auto [i, j, _] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
78 ++_;
79 }
80 }
81 }
82
83 int
84 bar (int _ = 0) // { dg-warning "unused parameter '_'" }
85 {
86 int _ = 1; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
87 return 0;
88 }
89
90 void
91 baz ()
92 {
93 if (int _ = bar ())
94 int _ = 2; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
95 else
96 int _ = 3; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
97 while (int _ = bar ())
98 int _ = 4; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
99 for (int _ = bar (); _; ++_)
100 int _ = 5; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
101 if (int _ = bar ())
102 {
103 int _ = 6; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
104 }
105 else
106 {
107 int _ = 7; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
108 }
109 while (int _ = bar ())
110 {
111 int _ = 8; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
112 }
113 for (int _ = bar (); _; ++_)
114 {
115 int _ = 9; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
116 }
117 }
118
119 void
120 qux (short _ = 0) // { dg-warning "unused parameter '_'" }
121 {
122 {
123 long _ = 1;
124 }
125 }
126
127 void
128 corge ()
129 {
130 auto b = [_ = 1] () { (void) _; }; // { dg-warning "lambda capture initializers only available with" "" { target c++11_down } }
131 // { dg-warning "variable 'b' set but not used" "" { target *-*-* } .-1 }
132 auto c = [_ = 2, _ = 3] () {};// { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
133 // { dg-warning "lambda capture initializers only available with" "" { target c++11_down } .-1 }
134 // { dg-warning "variable 'c' set but not used" "" { target *-*-* } .-2 }
135 {
136 int _ = 4;
137 auto d = [_, _ = 5] () {}; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
138 } // { dg-warning "lambda capture initializers only available with" "" { target c++11_down } .-1 }
139 // { dg-warning "variable 'd' set but not used" "" { target *-*-* } .-2 }
140 {
141 int _ = 5;
142 auto e = [_ = 6] () {}; // { dg-warning "lambda capture initializers only available with" "" { target c++11_down } }
143 } // { dg-warning "variable 'e' set but not used" "" { target *-*-* } .-1 }
144 }
145
146 namespace A {
147 int _ = 11;
148 }
149
150 void
151 garply (int x, // { dg-warning "unused parameter 'x'" }
152 int _, // { dg-warning "unused parameter '_'" }
153 int)
154 {
155 }
156
157 void
158 fred ()
159 {
160 try {
161 } catch (int _) {
162 int _ = 5; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
163 }
164 }
165
166 void
167 waldo (int _) // { dg-warning "unused parameter '_'" }
168 try
169 {
170 }
171 catch (int _) // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
172 {
173 int _ = 7;
174 }
175
176 void
177 grault (int _) // { dg-warning "unused parameter '_'" }
178 try
179 {
180 }
181 catch (int)
182 {
183 int _ = 8; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
184 }
185
186 void
187 plugh (int _) // { dg-warning "unused parameter '_'" }
188 try
189 {
190 int _ = 1; // { dg-warning "name-independent declarations only available with" "" { target c++23_down } }
191 }
192 catch (int)
193 {
194 }