diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-02-10 21:49:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-02-10 21:49:46 +0000 |
commit | 0bfe54fdc83b7b4e37c40e652d86d15aa89885b2 (patch) | |
tree | 11a7e3a0d742ebdf07a48547b142d277b176ef65 /test/Sema/flexible-array-init.c | |
parent | b53e3e71383233ebb68a6a736cbe8af6d8065700 (diff) |
GNU allows structs with flexible array members to be placed inside
arrays and other structs/unions as an extension. Downgrade our error
to a warning. Fixes PR3540.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64239 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/flexible-array-init.c')
-rw-r--r-- | test/Sema/flexible-array-init.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/test/Sema/flexible-array-init.c b/test/Sema/flexible-array-init.c index 99ef66abe9..909b856d17 100644 --- a/test/Sema/flexible-array-init.c +++ b/test/Sema/flexible-array-init.c @@ -1,4 +1,4 @@ -// RUN: clang -fsyntax-only -verify %s +// RUN: clang -fsyntax-only -pedantic -verify %s struct one { int a; int values[]; @@ -12,17 +12,21 @@ void test() { struct foo { int x; - int y[]; // expected-note 3 {{initialized flexible array member 'y' is here}} + int y[]; // expected-note 4 {{initialized flexible array member 'y' is here}} }; -struct bar { struct foo z; }; +struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}} struct foo a = { 1, { 2, 3, 4 } }; // Valid. struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}} -struct bar c = { { 1, { } } }; // Valid. -struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-error{{'struct foo' may not be used as an array element due to flexible array member}} +struct bar c = { { 1, { } } }; // Valid. \ + // 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}} struct foo desig_foo = { .y = {2, 3, 4} }; -struct bar desig_bar = { .z.y = { } }; +struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \ + // expected-warning{{zero size arrays are an extension}} 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}} @@ -36,3 +40,19 @@ struct polygon { }; struct polygon poly = { .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}} + +// 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}} +}; |