Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -pedantic -verify %s |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 2 | struct one { |
| 3 | int a; |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 4 | int values[]; // expected-note 3{{initialized flexible array member 'values' is here}} |
| 5 | } x = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 6 | |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 7 | struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 8 | |
| 9 | void test() { |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 10 | struct one x3 = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 11 | } |
| 12 | |
| 13 | struct foo { |
| 14 | int x; |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 15 | int y[]; // expected-note 6 {{initialized flexible array member 'y' is here}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 16 | }; |
Douglas Gregor | 0bfe54f | 2009-02-10 21:49:46 +0000 | [diff] [blame] | 17 | struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 18 | |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 19 | struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 20 | struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}} |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 21 | struct bar c = { { 1, { } } }; // // expected-warning{{flexible array initialization is a GNU extension}} \ |
Douglas Gregor | 0bfe54f | 2009-02-10 21:49:46 +0000 | [diff] [blame] | 22 | // expected-warning{{use of GNU empty initializer extension}} \ |
| 23 | // expected-warning{{zero size arrays are an extension}} |
| 24 | struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-warning{{'struct foo' may not be used as an array element due to flexible array member}} \ |
| 25 | // expected-error{{non-empty initialization of flexible array member inside subobject}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 26 | |
| 27 | struct foo desig_foo = { .y = {2, 3, 4} }; |
Douglas Gregor | 0bfe54f | 2009-02-10 21:49:46 +0000 | [diff] [blame] | 28 | struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \ |
| 29 | // expected-warning{{zero size arrays are an extension}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 30 | struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{non-empty initialization of flexible array member inside subobject}} |
| 31 | struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}} |
| 32 | |
| 33 | struct point { |
| 34 | int x, y; |
| 35 | }; |
| 36 | |
| 37 | struct polygon { |
| 38 | int numpoints; |
| 39 | struct point points[]; // expected-note{{initialized flexible array member 'points' is here}} |
| 40 | }; |
| 41 | struct polygon poly = { |
| 42 | .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}} |
Douglas Gregor | 0bfe54f | 2009-02-10 21:49:46 +0000 | [diff] [blame] | 43 | |
| 44 | // PR3540 |
| 45 | struct X { |
| 46 | int a; |
| 47 | int b; |
| 48 | char data[]; |
| 49 | }; |
| 50 | |
| 51 | struct Y { |
| 52 | int a:4; |
| 53 | int b:4; |
| 54 | int c; |
| 55 | int d; |
| 56 | int e; |
| 57 | struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}} |
| 58 | }; |