1 // RUN: clang-cc -fsyntax-only -verify -triple x86_64-unknown-unknown %s
3 int complete_array_from_init[] = { 1, 2, [10] = 5, 1, 2, [5] = 2, 6 };
5 int complete_array_from_init_check[((sizeof(complete_array_from_init) / sizeof(int)) == 13)? 1 : -1];
11 [ 8 ... 7 ] = 4, // expected-error{{array designator range [8, 7] is empty}}
13 [-1] = 6 // expected-error{{array designator value '-1' is negative}}
17 [10] = 1, // expected-error{{array designator index (10) exceeds array bounds (10)}}
21 [3] 2, // expected-warning{{use of GNU 'missing =' extension in designator}}
22 [5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}
32 x: 2.0, // expected-warning{{}}
33 .a = 4.0, // expected-error{{field designator 'a' does not refer to any field in type 'struct point'}}
37 [1] = 1.0 // expected-error{{array designator cannot initialize non-array type}}
40 struct point array[10] = {
43 [2].z = 3.0, // expected-error{{field designator 'z' does not refer to any field in type 'struct point'}}
46 struct point array2[10] = {
47 [10].x = 2.0, // expected-error{{array designator index (10) exceeds array bounds (10)}}
49 [4 ... 6] = { .x = 3, .y = 4.0 }
52 struct point array3[10] = {
53 .x = 5 // expected-error{{field designator cannot initialize a non-struct, non-union type}}
57 struct point top_left;
58 struct point bottom_right;
61 struct rect window = { .top_left.x = 1.0 };
63 struct rect windows[] = {
64 [2].top_left = { 1.0, 2.0 },
65 [4].bottom_right = { .y = 1.0 },
66 { { .y = 7.0, .x = 8.0 }, { .x = 5.0 } },
67 [3] = { .top_left = { 1.1, 2.2 }, .bottom_right = { .y = 1.1 } }
70 int windows_size[((sizeof(windows) / sizeof(struct rect)) == 6)? 1 : -1];
72 struct rect windows_bad[3] = {
73 [2].top_left = { { .x = 1.1 } }, // expected-error{{designator in initializer for scalar type}}
74 [1].top_left = { .x = 1.1 }
78 struct rect windows[10];
82 [5].windows[3].top_left.x = { 7.0 } // expected-warning{{braces around scalar initializer}}
86 struct wonky { int * ptr; } wonky ;
90 .window = { .top_left = { 1.0, 2.0 } },
91 { .x = 5.0, .y = 6.0 },
96 struct {int x,*y;} z[] = {[0].x = 2, &z[0].x};
98 struct outer { struct inner { int x, *y; } in, *inp; } zz[] = {
99 [0].in.x = 2, &zz[0].in.x, &zz[0].in,
100 0, &anint, &zz[1].in,
101 [3].in = { .y = &anint, .x = 17 },
102 [7].in.y = &anint, &zz[0].in,
103 [4].in.y = &anint, [5].in.x = 12
106 int zz_sizecheck[sizeof(zz) / sizeof(struct outer) == 8? 1 : -1 ];
108 struct disklabel_ops {
113 struct disklabel_ops disklabel64_ops = {
114 .labelsize = sizeof(struct disklabel_ops)
118 int bitwidth[] = { [(long long int)1] = 5, [(short int)2] = 2 };
119 int a[]= { [sizeof(int)] = 0 };
120 int a2[]= { [0 ... sizeof(int)] = 0 };
122 // Test warnings about initializers overriding previous initializers
128 int get8() { ++counter; return 8; }
132 [0] = (struct X){1, 2}, // expected-note{{previous initialization is here}}
133 [0].c = 3, // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
134 (struct X) {4, 5, 6}, // expected-note{{previous initialization is here}}
135 [1].b = get8(), // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
140 // FIXME: How do we test that this initializes the long properly?
141 union { char c; long l; } u1 = { .l = 0xFFFF };
143 extern float global_float;
145 struct XX { int a, *b; };
146 struct XY { int before; struct XX xx, *xp; float* after; } xy[] = {
147 0, 0, &xy[0].xx.a, &xy[0].xx, &global_float,
148 [1].xx = 0, &xy[1].xx.a, &xy[1].xx, &global_float,
149 0, // expected-note{{previous initialization is here}}
150 0, // expected-note{{previous initialization is here}}
151 [2].before = 0, // expected-warning{{initializer overrides prior initialization of this subobject}}
152 0, // expected-warning{{initializer overrides prior initialization of this subobject}}
153 &xy[2].xx.a, &xy[2].xx, &global_float
172 struct bar saloon = {
177 typedef unsigned char u_char;
178 typedef unsigned short u_short;
185 const union wibble wobble = { .arr2[0] = 0xffff,
189 const union wibble wobble2 = { .arr2 = {4, 5, 6}, 7 }; // expected-warning{{excess elements in union initializer}}
218 struct Enigma enigma = {
219 .double_ptr = &d0, &c0,
220 &f0, // expected-note{{previous}}
222 .float_ptr = &f0 // expected-warning{{overrides}}
227 /// Should use evaluate to fold aggressively and emit a warning if not an ice.
231 [ 0 ? crazy_x : 4] = 1