2009-12-15 23:14:24 +03:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
|
2009-02-05 01:46:25 +03:00
|
|
|
struct one {
|
|
|
|
int a;
|
2010-10-16 03:53:28 +04:00
|
|
|
int values[]; // expected-note 4{{initialized flexible array member 'values' is here}}
|
2009-03-20 03:32:56 +03:00
|
|
|
} x = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}}
|
2009-02-05 01:46:25 +03:00
|
|
|
|
2009-03-20 03:32:56 +03:00
|
|
|
struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}}
|
2009-02-05 01:46:25 +03:00
|
|
|
|
|
|
|
void test() {
|
2010-10-10 22:16:20 +04:00
|
|
|
struct one x3 = {5, {1, 2, 3}}; // \
|
|
|
|
// expected-warning{{flexible array initialization is a GNU extension}} \
|
|
|
|
// expected-error {{non-static initialization of a variable with flexible array member}}
|
2010-10-16 03:53:28 +04:00
|
|
|
struct one x3a = { 5 };
|
|
|
|
struct one x3b = { .a = 5 };
|
|
|
|
struct one x3c = { 5, {} }; // expected-warning{{use of GNU empty initializer extension}} \
|
|
|
|
// expected-warning{{flexible array initialization is a GNU extension}} \
|
|
|
|
// expected-warning{{zero size arrays are an extension}}
|
2009-02-05 01:46:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct foo {
|
|
|
|
int x;
|
2009-03-20 03:32:56 +03:00
|
|
|
int y[]; // expected-note 6 {{initialized flexible array member 'y' is here}}
|
2009-02-05 01:46:25 +03:00
|
|
|
};
|
2009-02-11 00:49:46 +03:00
|
|
|
struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}}
|
2009-02-05 01:46:25 +03:00
|
|
|
|
2009-03-20 03:32:56 +03:00
|
|
|
struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}}
|
2009-02-05 01:46:25 +03:00
|
|
|
struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}}
|
2009-03-20 03:32:56 +03:00
|
|
|
struct bar c = { { 1, { } } }; // // expected-warning{{flexible array initialization is a GNU extension}} \
|
2009-02-11 00:49:46 +03:00
|
|
|
// expected-warning{{use of GNU empty initializer extension}} \
|
|
|
|
// expected-warning{{zero size arrays are an extension}}
|
|
|
|
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}} \
|
|
|
|
// expected-error{{non-empty initialization of flexible array member inside subobject}}
|
2009-02-05 01:46:25 +03:00
|
|
|
|
|
|
|
struct foo desig_foo = { .y = {2, 3, 4} };
|
2009-02-11 00:49:46 +03:00
|
|
|
struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \
|
|
|
|
// expected-warning{{zero size arrays are an extension}}
|
2009-02-05 01:46:25 +03:00
|
|
|
struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{non-empty initialization of flexible array member inside subobject}}
|
|
|
|
struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}}
|
|
|
|
|
|
|
|
struct point {
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct polygon {
|
|
|
|
int numpoints;
|
|
|
|
struct point points[]; // expected-note{{initialized flexible array member 'points' is here}}
|
|
|
|
};
|
|
|
|
struct polygon poly = {
|
|
|
|
.points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}}
|
2009-02-11 00:49:46 +03:00
|
|
|
|
|
|
|
// PR3540
|
|
|
|
struct X {
|
|
|
|
int a;
|
|
|
|
int b;
|
|
|
|
char data[];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Y {
|
|
|
|
int a:4;
|
|
|
|
int b:4;
|
|
|
|
int c;
|
|
|
|
int d;
|
|
|
|
int e;
|
|
|
|
struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}}
|
|
|
|
};
|
2010-10-10 22:16:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
// PR8217
|
|
|
|
struct PR8217a {
|
|
|
|
int i;
|
|
|
|
char v[];
|
|
|
|
};
|
|
|
|
|
|
|
|
void PR8217() {
|
|
|
|
struct PR8217a foo1 = { .i = 0, .v = "foo" }; // expected-error {{non-static initialization of a variable with flexible array member}}
|
2010-10-16 03:53:28 +04:00
|
|
|
struct PR8217a foo2 = { .i = 0 };
|
2010-10-10 22:16:20 +04:00
|
|
|
struct PR8217a foo3 = { .i = 0, .v = { 'b', 'a', 'r', '\0' } }; // expected-error {{non-static initialization of a variable with flexible array member}}
|
|
|
|
struct PR8217a bar;
|
|
|
|
}
|
|
|
|
|