| 1 |
/* Test C23 support for empty initializers: valid use cases. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-std=c23 -pedantic-errors" } */ |
| 4 |
|
| 5 |
extern void exit (int); |
| 6 |
extern void abort (void); |
| 7 |
|
| 8 |
struct s { int a; }; |
| 9 |
struct s s = {}; |
| 10 |
int x = {}; |
| 11 |
float y = {}; |
| 12 |
void *p = {}; |
| 13 |
union u { int a; long b; }; |
| 14 |
union u z = {}; |
| 15 |
int aa[2] = {}; |
| 16 |
|
| 17 |
void |
| 18 |
f (int a) |
| 19 |
{ |
| 20 |
volatile int vla[a] = {}; |
| 21 |
struct s as = {}; |
| 22 |
int ax = {}; |
| 23 |
float ay = {}; |
| 24 |
void *ap = {}; |
| 25 |
union u az = {}; |
| 26 |
int aaa[2] = {}; |
| 27 |
for (int i = 0; i < a; i++) |
| 28 |
if (vla[i] != 0) |
| 29 |
abort (); |
| 30 |
if (as.a != 0) |
| 31 |
abort (); |
| 32 |
if (ax != 0) |
| 33 |
abort (); |
| 34 |
if (ay != 0) |
| 35 |
abort (); |
| 36 |
if (ap != 0) |
| 37 |
abort (); |
| 38 |
if (az.a != 0) |
| 39 |
abort (); |
| 40 |
if (aaa[0] != 0) |
| 41 |
abort (); |
| 42 |
if (aaa[1] != 0) |
| 43 |
abort (); |
| 44 |
if ((int) {} != 0) |
| 45 |
abort (); |
| 46 |
if ((float) {} != 0) |
| 47 |
abort (); |
| 48 |
if ((struct s) {}.a != 0) |
| 49 |
abort (); |
| 50 |
if ((union u) {}.a != 0) |
| 51 |
abort (); |
| 52 |
if ((int [5]) {}[2] != 0) |
| 53 |
abort (); |
| 54 |
/* Overwrite contents of vla before second call to make it more likely stack |
| 55 |
contents are nonzero if proper initialization did not occur. */ |
| 56 |
for (int i = 0; i < a; i++) |
| 57 |
vla[i] = -1; |
| 58 |
} |
| 59 |
|
| 60 |
int |
| 61 |
main (void) |
| 62 |
{ |
| 63 |
f (100); |
| 64 |
f (100); |
| 65 |
if (s.a != 0) |
| 66 |
abort (); |
| 67 |
if (x != 0) |
| 68 |
abort (); |
| 69 |
if (y != 0) |
| 70 |
abort (); |
| 71 |
if (p != 0) |
| 72 |
abort (); |
| 73 |
if (z.a != 0) |
| 74 |
abort (); |
| 75 |
if (aa[0] != 0) |
| 76 |
abort (); |
| 77 |
if (aa[1] != 0) |
| 78 |
abort (); |
| 79 |
exit (0); |
| 80 |
} |