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
diff --git a/test/Sema/flexible-array-init.c b/test/Sema/flexible-array-init.c
index 99ef66a..909b856 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 @@
 
 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 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}}
+};