flexible-array-init.c revision 7c53ca6e03833adab4465462b7d5c888741b715d
1// RUN: clang -fsyntax-only -pedantic -verify %s 2struct one { 3 int a; 4 int values[]; 5} x = {5, {1, 2, 3}}; 6 7struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{excess elements in struct initializer}} 8 9void test() { 10 struct one x3 = {5, {1, 2, 3}}; 11} 12 13struct foo { 14 int x; 15 int y[]; // expected-note 4 {{initialized flexible array member 'y' is here}} 16}; 17struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}} 18 19struct foo a = { 1, { 2, 3, 4 } }; // Valid. 20struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}} 21struct bar c = { { 1, { } } }; // Valid. \ 22 // expected-warning{{use of GNU empty initializer extension}} \ 23 // expected-warning{{zero size arrays are an extension}} 24struct 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}} 26 27struct foo desig_foo = { .y = {2, 3, 4} }; 28struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \ 29 // expected-warning{{zero size arrays are an extension}} 30struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{non-empty initialization of flexible array member inside subobject}} 31struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}} 32 33struct point { 34 int x, y; 35}; 36 37struct polygon { 38 int numpoints; 39 struct point points[]; // expected-note{{initialized flexible array member 'points' is here}} 40}; 41struct polygon poly = { 42 .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}} 43 44// PR3540 45struct X { 46 int a; 47 int b; 48 char data[]; 49}; 50 51struct 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}; 59