Debian Codegraph @

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

raw
1 // { dg-do compile }
2 // { dg-options -Wno-pedantic }
3
4 #define STR(s) #s
5 #define ASSERT(exp) \
6 ((exp) ? (void)0 : (void)(__builtin_printf ("%s:%i: assertion %s failed\n", \
7 __FILE__, __LINE__, STR(exp)), \
8 __builtin_abort ()))
9
10 typedef int int32_t __attribute__((mode (__SI__)));
11
12 struct Ax { int32_t n, a[]; };
13 struct AAx { int32_t i; Ax ax; };
14
15 int32_t i = 12345678;
16
17 int main ()
18 {
19 {
20 // OK. Does not assign any elements to flexible array.
21 Ax s = { 0 };
22 ASSERT (s.n == 0);
23 }
24 {
25 // OK only for statically allocated objects, otherwise error.
26 static Ax s = { 0, { } };
27 ASSERT (s.n == 0);
28 }
29 {
30 static Ax s = { 1, { 2 } };
31 ASSERT (s.n == 1 && s.a [0] == 2);
32 }
33 {
34 static Ax s = { 2, { 3, 4 } };
35 ASSERT (s.n = 2 && s.a [0] == 3 && s.a [1] == 4);
36 }
37 {
38 static Ax s = { 123, i };
39 ASSERT (s.n == 123 && s.a [0] == i);
40 }
41 {
42 static Ax s = { 456, { i } };
43 ASSERT (s.n == 456 && s.a [0] == i);
44 }
45 {
46 int32_t j = i + 1, k = j + 1;
47 static Ax s = { 3, { i, j, k } };
48 ASSERT (s.n == 3 && s.a [0] == i && s.a [1] == j && s.a [2] == k);
49 }
50
51 {
52 // OK. Does not assign any elements to flexible array.
53 AAx s = { 1, { 2 } };
54 ASSERT (s.i == 1 && s.ax.n == 2);
55 }
56 }