aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.dg/gnu99-init-1.c
blob: 009c8515f1ea939938664347972d4e1f1afa39e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Test for GNU extensions to C99 designated initializers */
/* Origin: Jakub Jelinek <jakub@redhat.com> */
/* { dg-do run } */
/* { dg-options "-std=gnu99" } */

typedef __SIZE_TYPE__ size_t;
extern int memcmp (const void *, const void *, size_t);
extern void abort (void);
extern void exit (int);

int a[][2][4] = { [2 ... 4][0 ... 1][2 ... 3] = 1, [2] = 2, [2][0][2] = 3 };
struct E {};
struct F { struct E H; };
struct G { int I; struct E J; int K; };
struct H { int I; struct F J; int K; };
struct G k = { .J = {}, 1 };
struct H l = { .J.H = {}, 2 };
struct H m = { .J = {}, 3 };
struct I { int J; int K[3]; int L; };
struct M { int N; struct I O[3]; int P; };
struct M n[] = { [0 ... 5].O[1 ... 2].K[0 ... 1] = 4, 5, 6, 7 };
struct M o[] = { [0 ... 5].O = { [1 ... 2].K[0 ... 1] = 4 },
		 [5].O[2].K[2] = 5, 6, 7 };
struct M p[] = { [0 ... 5].O[1 ... 2].K = { [0 ... 1] = 4 },
		 [5].O[2].K[2] = 5, 6, 7 };
int q[3][3] = { [0 ... 1] = { [1 ... 2] = 23 }, [1][2] = 24 };
int r[1] = { [0 ... 1 - 1] = 27 };

int main (void)
{
  int x, y, z;

  if (a[2][0][0] != 2 || a[2][0][2] != 3)
    abort ();
  a[2][0][0] = 0;
  a[2][0][2] = 1;
  for (x = 0; x <= 4; x++)
    for (y = 0; y <= 1; y++)
      for (z = 0; z <= 3; z++)
	if (a[x][y][z] != (x >= 2 && z >= 2))
	  abort ();
  if (k.I || l.I || m.I || k.K != 1 || l.K != 2 || m.K != 3)
    abort ();
  for (x = 0; x <= 5; x++)
    {
      if (n[x].N || n[x].O[0].J || n[x].O[0].L)
	abort ();
      for (y = 0; y <= 2; y++)
	if (n[x].O[0].K[y])
	  abort ();
      for (y = 1; y <= 2; y++)
	{
	  if (n[x].O[y].J)
	    abort ();
	  if (n[x].O[y].K[0] != 4)
	    abort ();
	  if (n[x].O[y].K[1] != 4)
	    abort ();
	  if ((x < 5 || y < 2) && (n[x].O[y].K[2] || n[x].O[y].L))
	    abort ();
	}
      if (x < 5 && n[x].P)
	abort ();
    }
  if (n[5].O[2].K[2] != 5 || n[5].O[2].L != 6 || n[5].P != 7)
    abort ();
  if (memcmp (n, o, sizeof (n)) || sizeof (n) != sizeof (o))
    abort ();
  if (memcmp (n, p, sizeof (n)) || sizeof (n) != sizeof (p))
    abort ();
  if (q[0][0] || q[0][1] != 23 || q[0][2] != 23)
    abort ();
  if (q[1][0] || q[1][1] != 23 || q[1][2] != 24)
    abort ();
  if (q[2][0] || q[2][1] || q[2][2])
    abort ();
  if (r[0] != 27)
    abort ();
  exit (0);
}