Debian Codegraph @

gcc/testsuite/g++.dg/ext/flexary9.C

raw
1 // { dg-do compile }
2 // { dg-options "-Wpedantic -Wno-error=pedantic" }
3
4 #include "flexary.h"
5
6 struct Sx {
7 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
8 };
9
10 // Verify that non-data members or static data members either before
11 // or after a zero-length array in an otherwise empty struct don't
12 // suppress the diagnostic.
13 struct Sx2 {
14 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
15 typedef int I;
16 };
17
18 struct Sx3 {
19 typedef int I;
20 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
21 };
22
23 struct Sx4 {
24 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
25 enum E { e };
26 };
27
28 struct Sx5 {
29 enum E { e };
30 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
31 };
32
33 struct Sx6 {
34 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
35 static int i;
36 };
37
38 struct Sx7 {
39 static int i;
40 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
41 };
42
43 struct Sx8 {
44 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
45 Sx8 () { }
46 };
47
48 struct Sx9 {
49 Sx9 () { }
50 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
51 };
52
53 struct Sx10 {
54 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
55 virtual ~Sx10 () { }
56 };
57
58 struct Sx11 {
59 virtual ~Sx11 () { }
60 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
61 };
62
63 struct Sx12 {
64 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
65 virtual void foo () = 0;
66 };
67
68 struct Sx13 {
69 virtual void foo () = 0;
70 int a[0]; // { dg-warning "zero-size|in an otherwise empty" }
71 };
72
73 struct Sx14 {
74 int a[0][1]; // { dg-warning "zero-size|in an otherwise empty" }
75 };
76
77 struct Sx15 {
78 typedef int A[0]; // { dg-warning "zero-size" }
79 A a; // { dg-warning "in an otherwise empty" }
80 };
81
82 // Verify also that a zero-size array doesn't suppress the diagnostic.
83 struct Sx16 {
84 int a_0 [0]; // { dg-warning "zero-size|in an otherwise empty" }
85 int a_x [0]; // { dg-warning "zero-size array" }
86 };
87
88 struct Sx17 {
89 int a_x [0]; // { dg-warning "zero-size|in an otherwise empty" }
90 int a_0 [0]; // { dg-warning "zero-size array" }
91 };
92
93 // Empty structs are a GCC extension that (in C++ only) is treated
94 // as if it had a single member of type char. Therefore, a struct
95 // containing a zero-length array followed by an empty struct
96 // is diagnosed to prevent the former subobject from sharing space
97 // with the latter.
98 struct Sx18 {
99 int a_x [0]; // { dg-warning "zero-size array" }
100 struct S { };
101 };
102
103 // Anonymous structs and unions are another GCC extension. Since
104 // they cannot be named and thus used to store the size of a zero
105 // length array member, a struct containing both is diagnosed as
106 // if the zero-length array appeared alone.
107 struct Sx19 {
108 struct S { };
109 union U { };
110 int a_x [0]; // { dg-warning "zero-size|in an otherwise empty" }
111 };
112
113 // Unlike in the case above, a named member of an anonymous struct
114 // prevents a subsequent zero-length array from being diagnosed.
115 struct Sx20 {
116 struct S { } s;
117 int a_x [0]; // { dg-warning "zero-size array" }
118 };
119
120 struct Sx21 {
121 int a_x [0]; // { dg-warning "zero-size array|not at end" }
122 struct S { } s;
123 };
124
125 struct Sx22 {
126 int a_x [0]; // { dg-warning "zero-size array|not at end" }
127 union { int i; };
128 };
129
130 struct Sx23 {
131 union { int i; };
132 int a_x [0]; // { dg-warning "zero-size array" }
133 };
134
135 // The following causes an incomplete type error error and a zero-size
136 // array warning.
137 struct Sx24 {
138 struct S;
139 S a_x [0]; // { dg-error "5:field .a_x. has incomplete type" }
140 // { dg-warning "zero-size array" "" { target *-*-* } .-1 }
141 };
142
143 struct Sx25 {
144 struct S { };
145 S a_x [0]; // { dg-warning "zero-size array" }
146 };
147
148 struct Sx26 {
149 struct { }
150 a_x [0]; // { dg-warning "zero-size array" }
151 };
152
153 struct Sx27 {
154 int i;
155 struct { }
156 a_x [0]; // { dg-warning "zero-size array" }
157 };
158
159 ASSERT_AT_END (Sx27, a_x);
160
161 struct Sx28 {
162 struct { }
163 a_x [0]; // { dg-warning "zero-size array|not at end" }
164 int i;
165 };
166
167 struct Sx29 {
168 // Pointer to an array of zero size.
169 int (*a_x)[0]; // { dg-warning "zero-size array" }
170 };
171
172 struct Sx30 {
173 // Reference to an array of zero size.
174 int (&a_x)[0]; // { dg-warning "zero-size array" }
175 };
176
177 struct Sx31 {
178 int a [0]; // { dg-warning "zero-size array|not at end" }
179 unsigned i: 1;
180 };
181
182 struct Sx32 {
183 unsigned i: 1;
184 int a [0]; // { dg-warning "zero-size array" }
185 };
186
187 ASSERT_AT_END (Sx32, a);
188
189 struct Sx33 {
190 int a [0]; // { dg-warning "zero-size array|otherwise empty" }
191 friend int foo ();
192 };
193
194 struct Sx34 {
195 friend int foo ();
196 int a [0]; // { dg-warning "zero-size array|otherwise empty" }
197 };
198
199 // Verify that intervening non-field declarations of members other
200 // than non-static data members don't affect the diagnostics.
201 struct Sx35 {
202 int a[0]; // { dg-warning "zero-size array|not at end" }
203 typedef int I;
204 int n;
205 };
206
207 struct Sx36 {
208 int n;
209 typedef int I;
210 int a[0]; // { dg-warning "zero-size array" }
211 };
212
213 ASSERT_AT_END (Sx36, a);
214
215 struct Sx37 {
216 int a[0]; // { dg-warning "zero-size array|not at end" }
217 enum E { };
218 int n;
219 };
220
221 struct Sx38 {
222 int n;
223 enum E { };
224 int a[0]; // { dg-warning "zero-size array" }
225 };
226
227 ASSERT_AT_END (Sx38, a);
228
229 struct Sx39 {
230 int a[0]; // { dg-warning "zero-size array|not at end" }
231 struct S;
232 int n;
233 };
234
235 struct Sx40 {
236 int n;
237 struct S;
238 int a[0]; // { dg-warning "zero-size array" }
239 };
240
241 ASSERT_AT_END (Sx40, a);
242
243 struct Sx41 {
244 int a[0]; // { dg-warning "zero-size array|not at end" }
245 static int i;
246 int n;
247 };
248
249 struct Sx42 {
250 int n;
251 static int i;
252 int a[0]; // { dg-warning "zero-size array" }
253 };
254
255 ASSERT_AT_END (Sx42, a);
256
257 struct Sx43 {
258 int a[0]; // { dg-warning "zero-size array|not at end" }
259 Sx43 ();
260 int n;
261 };
262
263 struct Sx44 {
264 int n;
265 Sx44 ();
266 int a[0]; // { dg-warning "zero-size array" }
267 };
268
269 ASSERT_AT_END (Sx44, a);
270
271 struct S_S_S_x {
272 struct A {
273 struct B {
274 int a[0]; // { dg-warning "zero-size array" }
275 } b; // { dg-warning "invalid use" }
276 } a;
277 };
278
279 // Since members of an anonymous struct or union are considered to be
280 // members of the enclosing union the below defintions are valid and
281 // must be accepted.
282
283 struct Anon1 {
284 int n;
285 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct|invalid use \[^\n\r\]* with a zero-size array" }
286 int good[0]; // { dg-warning "forbids zero-size array" }
287 };
288 };
289
290 ASSERT_AT_END (Anon1, good);
291
292 struct Anon2 {
293 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct|invalid use" }
294 int n;
295 struct { // { dg-warning "12:ISO C\\+\\+ prohibits anonymous struct" }
296 int good[0]; // { dg-warning "zero-size array" }
297 };
298 };
299 };
300
301 ASSERT_AT_END (Anon2, good);
302
303 struct Anon3 {
304 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct|invalid use" }
305 struct { // { dg-warning "12:ISO C\\+\\+ prohibits anonymous struct" }
306 int n;
307 int good[0]; // { dg-warning "zero-size array" }
308 };
309 };
310 };
311
312 ASSERT_AT_END (Anon3, good);
313
314 struct Anon4 {
315 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct" }
316 int in_empty_struct[0]; // { dg-warning "zero-size array|in an otherwise empty" }
317 };
318 };
319
320 struct Anon5 {
321 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct" }
322 int not_at_end[0]; // { dg-warning "zero-size array|not at end" }
323 };
324 int n;
325 };
326
327 struct Anon6 {
328 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct" }
329 struct { // { dg-warning "12:ISO C\\+\\+ prohibits anonymous struct" }
330 int not_at_end[0]; // { dg-warning "zero-size array|not at end" }
331 };
332 int n;
333 };
334 };
335
336
337 struct Anon7 {
338 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct" }
339 struct { // { dg-warning "12:ISO C\\+\\+ prohibits anonymous struct" }
340 int not_at_end[0]; // { dg-warning "zero-size array|not at end" }
341 };
342 };
343 int n;
344 };
345
346
347 struct Six {
348 int i;
349 int a[0]; // { dg-warning "zero-size array" }
350 };
351
352 ASSERT_AT_END (Six, a);
353
354 class Cx {
355 int a[0]; // { dg-warning "zero-size array" }
356 };
357
358 class Cix {
359 int i;
360 int a[0]; // { dg-warning "zero-size array" }
361 };
362
363 struct Sxi {
364 int a[0]; // { dg-warning "zero-size array|not at end" }
365 int i;
366 };
367
368 struct S0 {
369 int a[0]; // { dg-warning "zero-size array" }
370 };
371
372 struct S0i {
373 int a[0]; // { dg-warning "zero-size array" }
374 int i;
375 };
376
377 struct S_a0_ax {
378 int a1[0]; // { dg-warning "zero-size array" }
379 int ax[0]; // { dg-warning "zero-size array" }
380 };
381
382 struct S_a0_i_ax {
383 int a1[0]; // { dg-warning "zero-size array" }
384 int i;
385 int ax[0]; // { dg-warning "zero-size array" }
386 };
387
388 ASSERT_AT_END (S_a0_i_ax, ax);
389
390 struct Si_a0_ax {
391 int i;
392 int a1[0]; // { dg-warning "zero-size array" }
393 int ax[0]; // { dg-warning "zero-size array" }
394 };
395
396 ASSERT_AT_END (Si_a0_ax, ax);
397
398 struct S_u0_ax {
399 union { } u[0]; // { dg-warning "zero-size array" }
400 int ax[0]; // { dg-warning "zero-size array" }
401 };
402
403 struct S_a1_s2 {
404 int a[1];
405 int b[2];
406 };