blob: afe31fb8294fa61bddf8d8c33288acc9fa6e859f [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -pedantic -verify %s
Douglas Gregoreeb15d42009-02-04 22:46:25 +00002struct one {
3 int a;
Douglas Gregora6457962009-03-20 00:32:56 +00004 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 Gregoreeb15d42009-02-04 22:46:25 +00006
Douglas Gregora6457962009-03-20 00:32:56 +00007struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}}
Douglas Gregoreeb15d42009-02-04 22:46:25 +00008
9void test() {
Douglas Gregora6457962009-03-20 00:32:56 +000010 struct one x3 = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}}
Douglas Gregoreeb15d42009-02-04 22:46:25 +000011}
12
13struct foo {
14 int x;
Douglas Gregora6457962009-03-20 00:32:56 +000015 int y[]; // expected-note 6 {{initialized flexible array member 'y' is here}}
Douglas Gregoreeb15d42009-02-04 22:46:25 +000016};
Douglas Gregor0bfe54f2009-02-10 21:49:46 +000017struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}}
Douglas Gregoreeb15d42009-02-04 22:46:25 +000018
Douglas Gregora6457962009-03-20 00:32:56 +000019struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}}
Douglas Gregoreeb15d42009-02-04 22:46:25 +000020struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}}
Douglas Gregora6457962009-03-20 00:32:56 +000021struct bar c = { { 1, { } } }; // // expected-warning{{flexible array initialization is a GNU extension}} \
Douglas Gregor0bfe54f2009-02-10 21:49:46 +000022 // 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}}
Douglas Gregoreeb15d42009-02-04 22:46:25 +000026
27struct foo desig_foo = { .y = {2, 3, 4} };
Douglas Gregor0bfe54f2009-02-10 21:49:46 +000028struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \
29 // expected-warning{{zero size arrays are an extension}}
Douglas Gregoreeb15d42009-02-04 22:46:25 +000030struct 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}}
Douglas Gregor0bfe54f2009-02-10 21:49:46 +000043
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};