| 1 |
/* Test for GNU extensions to C99 designated initializers */ |
| 2 |
/* Origin: Jakub Jelinek <[email protected]> */ |
| 3 |
/* { dg-do run } */ |
| 4 |
/* { dg-options "-std=gnu99" } */ |
| 5 |
|
| 6 |
typedef __SIZE_TYPE__ size_t; |
| 7 |
extern int memcmp (const void *, const void *, size_t); |
| 8 |
extern void abort (void); |
| 9 |
extern void exit (int); |
| 10 |
|
| 11 |
int a[][2][4] = { [2 ... 4][0 ... 1][2 ... 3] = 1, [2] = 2, [2][0][2] = 3 }; |
| 12 |
struct E {}; |
| 13 |
struct F { struct E H; }; |
| 14 |
struct G { int I; struct E J; int K; }; |
| 15 |
struct H { int I; struct F J; int K; }; |
| 16 |
struct G k = { .J = {}, 1 }; |
| 17 |
struct H l = { .J.H = {}, 2 }; |
| 18 |
struct H m = { .J = {}, 3 }; |
| 19 |
struct I { int J; int K[3]; int L; }; |
| 20 |
struct M { int N; struct I O[3]; int P; }; |
| 21 |
struct M n[] = { [0 ... 5].O[1 ... 2].K[0 ... 1] = 4, 5, 6, 7 }; |
| 22 |
struct M o[] = { [0 ... 5].O = { [1 ... 2].K[0 ... 1] = 4 }, |
| 23 |
[5].O[2].K[2] = 5, 6, 7 }; |
| 24 |
struct M p[] = { [0 ... 5].O[1 ... 2].K = { [0 ... 1] = 4 }, |
| 25 |
[5].O[2].K[2] = 5, 6, 7 }; |
| 26 |
int q[3][3] = { [0 ... 1] = { [1 ... 2] = 23 }, [1][2] = 24 }; |
| 27 |
int r[1] = { [0 ... 1 - 1] = 27 }; |
| 28 |
|
| 29 |
int main (void) |
| 30 |
{ |
| 31 |
int x, y, z; |
| 32 |
|
| 33 |
if (a[2][0][0] != 2 || a[2][0][2] != 3) |
| 34 |
abort (); |
| 35 |
a[2][0][0] = 0; |
| 36 |
a[2][0][2] = 1; |
| 37 |
for (x = 0; x <= 4; x++) |
| 38 |
for (y = 0; y <= 1; y++) |
| 39 |
for (z = 0; z <= 3; z++) |
| 40 |
if (a[x][y][z] != (x >= 2 && z >= 2)) |
| 41 |
abort (); |
| 42 |
if (k.I || l.I || m.I || k.K != 1 || l.K != 2 || m.K != 3) |
| 43 |
abort (); |
| 44 |
for (x = 0; x <= 5; x++) |
| 45 |
{ |
| 46 |
if (n[x].N || n[x].O[0].J || n[x].O[0].L) |
| 47 |
abort (); |
| 48 |
for (y = 0; y <= 2; y++) |
| 49 |
if (n[x].O[0].K[y]) |
| 50 |
abort (); |
| 51 |
for (y = 1; y <= 2; y++) |
| 52 |
{ |
| 53 |
if (n[x].O[y].J) |
| 54 |
abort (); |
| 55 |
if (n[x].O[y].K[0] != 4) |
| 56 |
abort (); |
| 57 |
if (n[x].O[y].K[1] != 4) |
| 58 |
abort (); |
| 59 |
if ((x < 5 || y < 2) && (n[x].O[y].K[2] || n[x].O[y].L)) |
| 60 |
abort (); |
| 61 |
} |
| 62 |
if (x < 5 && n[x].P) |
| 63 |
abort (); |
| 64 |
} |
| 65 |
if (n[5].O[2].K[2] != 5 || n[5].O[2].L != 6 || n[5].P != 7) |
| 66 |
abort (); |
| 67 |
if (memcmp (n, o, sizeof (n)) || sizeof (n) != sizeof (o)) |
| 68 |
abort (); |
| 69 |
if (memcmp (n, p, sizeof (n)) || sizeof (n) != sizeof (p)) |
| 70 |
abort (); |
| 71 |
if (q[0][0] || q[0][1] != 23 || q[0][2] != 23) |
| 72 |
abort (); |
| 73 |
if (q[1][0] || q[1][1] != 23 || q[1][2] != 24) |
| 74 |
abort (); |
| 75 |
if (q[2][0] || q[2][1] || q[2][2]) |
| 76 |
abort (); |
| 77 |
if (r[0] != 27) |
| 78 |
abort (); |
| 79 |
exit (0); |
| 80 |
} |