1 /* Test for compound literals: in C99 only. Test for valid uses. */
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
4 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
6 extern void abort (void);
7 extern void exit (int);
9 struct s { int a; int b; };
10 union u { int c; int d; };
12 int *i0a = &(int) { 0 };
13 int *i0b = &(int) { 0 };
14 int *i1a = &(int) { 1 };
15 int *i1b = &(int) { 1 };
16 const int *i0c = &(const int) { 0 };
18 struct s *s0 = &(struct s) { 1, 2 };
19 struct s *s1 = &(struct s) { 1, 2 };
20 const struct s *s2 = &(const struct s) { 1, 2 };
22 union u *u0 = &(union u) { 3 };
23 union u *u1 = &(union u) { 3 };
24 const union u *u2 = &(const union u) { 3 };
26 int *a0 = (int []) { 1, 2, 3 };
27 const int *a1 = (const int []) { 1, 2, 3 };
29 char *p = (char []){ "foo" };
34 if (i0a == i0b || i0a == i0c || i0b == i0c)
38 if (*i0a != 0 || *i0b != 0 || *i1a != 1 || *i1b != 1 || *i0c != 0)
42 if (*i0a != 1 || *i0b != 0 || *i1a != 0 || *i1b != 1 || *i0c != 0)
44 if (s0 == s1 || s1 == s2 || s2 == s0)
46 if (s0->a != 1 || s0->b != 2 || s1->a != 1 || s1->b != 2
47 || s2->a != 1 || s2->b != 2)
51 if (s0->a != 2 || s0->b != 2 || s1->a != 1 || s1->b != 1
52 || s2->a != 1 || s2->b != 2)
54 if (u0 == u1 || u1 == u2 || u2 == u0)
56 if (u0->c != 3 || u1->c != 3 || u2->c != 3)
59 if (u0->d != 2 || u1->c != 3 || u2->c != 3)
63 if (a0[0] != 1 || a0[1] != 2 || a0[2] != 3
64 || a1[0] != 1 || a1[1] != 2 || a1[2] != 3)
67 if (a0[0] != 3 || a0[1] != 2 || a0[2] != 3
68 || a1[0] != 1 || a1[1] != 2 || a1[2] != 3)
70 if (p[0] != 'f' || p[1] != 'o' || p[2] != 'o' || p[3] != 0)
73 if (p[0] != 'g' || p[1] != 'o' || p[2] != 'o' || p[3] != 0)
75 if (sizeof((int []) { 1, 2 ,3 }) != 3 * sizeof(int))
77 if (sizeof((int []) { [3] = 4 }) != 4 * sizeof(int))
80 for (int i = 0; i < 3; i++) {
81 struct s *x = &(struct s) { 1, i };
82 if (x->a != 1 || x->b != i)
86 if (x->a != 2 || x->b != i - 1)
93 for (int i = 0; i < 4; i++) {
94 int *x = (int []){ 0, i, i + 2, i - 3 };
95 if (x[0] != 0 || x[1] != i || x[2] != i + 2 || x[3] != i - 3)
101 if (x[0] != i || x[1] != i * (i + 2) || x[2] != 5 || x[3] != i + 4)
108 (struct s) { 0, 1 }.a = 3;
109 (union u) { 3 }.c = 4;
110 (int []){ 1, 2 }[0] = 0;