Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame^] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | struct one { |
| 3 | int a; |
| 4 | int values[]; |
| 5 | } x = {5, {1, 2, 3}}; |
| 6 | |
| 7 | struct one x2 = { 5, 1, 2, 3 }; // expected-error{{excess elements in struct initializer}} |
| 8 | |
| 9 | void test() { |
| 10 | struct one x3 = {5, {1, 2, 3}}; |
| 11 | } |
| 12 | |
| 13 | struct foo { |
| 14 | int x; |
| 15 | int y[]; // expected-note{{initialized flexible array member 'y' is here}} |
| 16 | }; |
| 17 | struct bar { struct foo z; }; |
| 18 | |
| 19 | struct foo a = { 1, { 2, 3, 4 } }; // Valid. |
| 20 | struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}} |
| 21 | struct bar c = { { 1, { } } }; // Valid. |
| 22 | struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-error{{'struct foo' may not be used as an array element due to flexible array member}} |
| 23 | |
| 24 | struct foo desig_foo = { .y = {2, 3, 4} }; |
| 25 | struct bar desig_bar = { .z.y = { } }; |
| 26 | struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{non-empty initialization of flexible array member inside subobject}} |
| 27 | struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}} |
| 28 | |
| 29 | struct point { |
| 30 | int x, y; |
| 31 | }; |
| 32 | |
| 33 | struct polygon { |
| 34 | int numpoints; |
| 35 | struct point points[]; // expected-note{{initialized flexible array member 'points' is here}} |
| 36 | }; |
| 37 | struct polygon poly = { |
| 38 | .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}} |