Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -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 | c6eddf5 | 2010-10-15 23:53:28 +0000 | [diff] [blame] | 4 | int values[]; // expected-note 4{{initialized flexible array member 'values' is here}} |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 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() { |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 10 | struct one x3 = {5, {1, 2, 3}}; // expected-error{{initialization of flexible array member is not allowed}} |
Douglas Gregor | c6eddf5 | 2010-10-15 23:53:28 +0000 | [diff] [blame] | 11 | struct one x3a = { 5 }; |
| 12 | struct one x3b = { .a = 5 }; |
| 13 | struct one x3c = { 5, {} }; // expected-warning{{use of GNU empty initializer extension}} \ |
| 14 | // expected-warning{{flexible array initialization is a GNU extension}} \ |
| 15 | // expected-warning{{zero size arrays are an extension}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | struct foo { |
| 19 | int x; |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 20 | int y[]; // expected-note 8 {{initialized flexible array member 'y' is here}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 21 | }; |
Douglas Gregor | 0bfe54f | 2009-02-10 21:49:46 +0000 | [diff] [blame] | 22 | 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] | 23 | |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 24 | struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}} |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 25 | struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{initialization of flexible array member is not allowed}} |
Douglas Gregor | a645796 | 2009-03-20 00:32:56 +0000 | [diff] [blame] | 26 | 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] | 27 | // expected-warning{{use of GNU empty initializer extension}} \ |
| 28 | // expected-warning{{zero size arrays are an extension}} |
| 29 | 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}} \ |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 30 | // expected-error{{initialization of flexible array member is not allowed}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 31 | |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 32 | struct foo desig_foo = { .y = {2, 3, 4} }; // expected-warning{{flexible array initialization is a GNU extension}} |
Douglas Gregor | 0bfe54f | 2009-02-10 21:49:46 +0000 | [diff] [blame] | 33 | struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \ |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 34 | // expected-warning{{zero size arrays are an extension}} \ |
| 35 | // expected-warning{{flexible array initialization is a GNU extension}} |
| 36 | struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{initialization of flexible array member is not allowed}} |
Douglas Gregor | eeb15d4 | 2009-02-04 22:46:25 +0000 | [diff] [blame] | 37 | struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}} |
| 38 | |
| 39 | struct point { |
| 40 | int x, y; |
| 41 | }; |
| 42 | |
| 43 | struct polygon { |
| 44 | int numpoints; |
| 45 | struct point points[]; // expected-note{{initialized flexible array member 'points' is here}} |
| 46 | }; |
| 47 | struct polygon poly = { |
| 48 | .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}} |
Douglas Gregor | 0bfe54f | 2009-02-10 21:49:46 +0000 | [diff] [blame] | 49 | |
| 50 | // PR3540 |
| 51 | struct X { |
| 52 | int a; |
| 53 | int b; |
| 54 | char data[]; |
| 55 | }; |
| 56 | |
| 57 | struct Y { |
| 58 | int a:4; |
| 59 | int b:4; |
| 60 | int c; |
| 61 | int d; |
| 62 | int e; |
| 63 | struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}} |
| 64 | }; |
Chris Lattner | 16c5dea | 2010-10-10 18:16:20 +0000 | [diff] [blame] | 65 | |
| 66 | |
| 67 | // PR8217 |
| 68 | struct PR8217a { |
| 69 | int i; |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 70 | char v[]; // expected-note 2 {{initialized flexible array member 'v' is here}} |
Chris Lattner | 16c5dea | 2010-10-10 18:16:20 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | void PR8217() { |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 74 | struct PR8217a foo1 = { .i = 0, .v = "foo" }; // expected-error {{initialization of flexible array member is not allowed}} |
Douglas Gregor | c6eddf5 | 2010-10-15 23:53:28 +0000 | [diff] [blame] | 75 | struct PR8217a foo2 = { .i = 0 }; |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 76 | struct PR8217a foo3 = { .i = 0, .v = { 'b', 'a', 'r', '\0' } }; // expected-error {{initialization of flexible array member is not allowed}} |
Chris Lattner | 16c5dea | 2010-10-10 18:16:20 +0000 | [diff] [blame] | 77 | struct PR8217a bar; |
| 78 | } |
| 79 | |
Eli Friedman | f40fd6b | 2011-08-23 22:24:57 +0000 | [diff] [blame] | 80 | typedef struct PR10648 { |
| 81 | unsigned long n; |
| 82 | int v[]; // expected-note {{initialized flexible array member 'v' is here}} |
| 83 | } PR10648; |
| 84 | int f10648() { |
| 85 | return (PR10648){2, {3, 4}}.v[1]; // expected-error {{initialization of flexible array member is not allowed}} |
| 86 | } |
| 87 | |
| 88 | struct FlexWithUnnamedBitfield { int : 10; int x; int y[]; }; // expected-note {{initialized flexible array member 'y' is here}} |
| 89 | void TestFlexWithUnnamedBitfield() { |
| 90 | struct FlexWithUnnamedBitfield x = {10, {3}}; // expected-error {{initialization of flexible array member is not allowed}} |
| 91 | } |