blob: 5efb4444956bc3612d756c639a02cc2788b83abb [file] [log] [blame]
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001// RUN: clang -fsyntax-only -verify %s
2
3int iarray[10] = {
4 [0] = 1,
5 [1 ... 5] = 2,
6 [ 6 ... 6 ] = 3,
7 [ 8 ... 7 ] = 4, // expected-error{{array designator range [8, 7] is empty}}
8 [10] = 5,
9 [-1] = 6 // expected-error{{array designator value '-1' is negative}}
10};
11
12int iarray2[10] = {
13 [10] = 1, // expected-error{{array designator index (10) exceeds array bounds (10)}}
14 [5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}
15};
16
17struct point {
18 double x;
19 double y;
20};
21
22struct point p1 = {
23 .y = 1.0,
24 x: 2.0,
25 .a = 4.0, // expected-error{{field designator 'a' does not refer to any field in type 'struct point'}}
26
27 [1] = 1.0 // expected-error{{array designator cannot initialize non-array type}}
28};
29
30struct point array[10] = {
31 [0].x = 1.0,
32 [1].y = 2.0,
33 [2].z = 3.0, // expected-error{{field designator 'z' does not refer to any field in type 'struct point'}}
34 [10].x = 2.0, // expected-error{{array designator index (10) exceeds array bounds (10)}}
35 [4 ... 5].y = 2.0,
36 [4 ... 6] = { .x = 3, .y = 4.0 },
37 .x = 5 // expected-error{{field designator cannot initialize a non-struct, non-union type}}
38};
39
40struct rect {
41 struct point top_left;
42 struct point bottom_right;
43};
44
45struct rect window = { .top_left.x = 1.0 };
46
47struct rect windows[] = {
48 [2].top_left = { 1.0, 2.0 },
49 [4].bottom_right = { .y = 1.0 },
50 { { .y = 7.0, .x = 8.0 }, { .x = 5.0 } },
51 [3] = { .top_left = { 1.1, 2.2 }, .bottom_right = { .y = 1.1 } }
52};
53
54int windows_size[((sizeof(windows) / sizeof(struct rect)) == 6)? 1 : -1];
55
56struct rect windows_bad[3] = {
57 [2].top_left = { { .x = 1.1 } }, // expected-error{{designator in initializer for scalar type}}
58 [1].top_left = { .x = 1.1 }
59};
60
61struct gui {
62 struct rect windows[10];
63};
64
65struct gui gui[] = {
66 [5].windows[3].top_left.x = { 7.0 } // expected-warning{{braces around scalar initializer}}
67};
68
69struct translator {
70 struct wonky { int * ptr; } wonky ;
71 struct rect window;
72 struct point offset;
73} tran = {
74 .window = { .top_left = { 1.0, 2.0 } },
75 { .x = 5.0, .y = 6.0 },
76 .wonky = { 0 }
77};
78