summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/flexible-array-init.c
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-04 22:46:25 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-04 22:46:25 +0000
commitfc4f8a183444747b3abea2e5a1dcca83b116dcd3 (patch)
treeea2ede6d592437d1e8ed5ebd195db837b9ec2bb0 /clang/test/Sema/flexible-array-init.c
parent82f071faa7340828da5729736e1d2b3180f3b63e (diff)
downloadbcm5719-llvm-fc4f8a183444747b3abea2e5a1dcca83b116dcd3.tar.gz
bcm5719-llvm-fc4f8a183444747b3abea2e5a1dcca83b116dcd3.zip
Implement semantic analysis for the GNU flexible array initialization
extension. The interaction with designated initializers is a bit... interesting... but we follow GNU's lead and don't permit too much crazy code in this area. Also, make the "excess initializers" error message a bit more informative. Addresses PR2561: http://llvm.org/bugs/show_bug.cgi?id=2561 llvm-svn: 63785
Diffstat (limited to 'clang/test/Sema/flexible-array-init.c')
-rw-r--r--clang/test/Sema/flexible-array-init.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/clang/test/Sema/flexible-array-init.c b/clang/test/Sema/flexible-array-init.c
new file mode 100644
index 00000000000..9ef6eb3bc00
--- /dev/null
+++ b/clang/test/Sema/flexible-array-init.c
@@ -0,0 +1,38 @@
+// RUN: clang -fsyntax-only -verify %s
+struct one {
+ int a;
+ int values[];
+} x = {5, {1, 2, 3}};
+
+struct one x2 = { 5, 1, 2, 3 }; // expected-error{{excess elements in struct initializer}}
+
+void test() {
+ struct one x3 = {5, {1, 2, 3}};
+}
+
+struct foo {
+ int x;
+ int y[]; // expected-note{{initialized flexible array member 'y' is here}}
+};
+struct bar { struct foo z; };
+
+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 foo desig_foo = { .y = {2, 3, 4} };
+struct bar desig_bar = { .z.y = { } };
+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}}
OpenPOWER on IntegriCloud