summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/c-parse.in7
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/init-desig-obs-1.c19
-rw-r--r--gcc/testsuite/gcc.dg/init-desig-obs-2.c11
-rw-r--r--gcc/testsuite/gcc.dg/init-desig-obs-3.c11
6 files changed, 59 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9ffe392ef73..001043dea99 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2004-10-25 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ PR c/16667
+ * c-parse.in (array_designator): New.
+ (designator): Use it.
+ (initelt): Only permit array_designator without '=', not ".foo".
+
2004-10-25 Kenneth Zadeck <zadeck@naturalbridge.com>
* gcc/Makefile.in: removed ggc for cgraphunit.
* gcc/cgraph.c.dump_cgraph_node: removed static var analysis.
diff --git a/gcc/c-parse.in b/gcc/c-parse.in
index f59db976e33..7f6f4f491d7 100644
--- a/gcc/c-parse.in
+++ b/gcc/c-parse.in
@@ -1445,7 +1445,7 @@ initelt:
designator_list '=' initval
{ if (pedantic && !flag_isoc99)
pedwarn ("ISO C90 forbids specifying subobject to initialize"); }
- | designator initval
+ | array_designator initval
{ if (pedantic)
pedwarn ("obsolete use of designated initializer without %<=%>"); }
| identifier ':'
@@ -1475,7 +1475,10 @@ designator_list:
designator:
'.' identifier
{ set_init_label ($2); }
- | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
+ | array_designator
+
+array_designator:
+ '[' expr_no_commas ELLIPSIS expr_no_commas ']'
{ set_init_index ($2.value, $4.value);
if (pedantic)
pedwarn ("ISO C forbids specifying range of elements to initialize"); }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 19c32bb3d3c..68b98b29c15 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2004-10-25 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ PR c/16667
+ * gcc.dg/init-desig-obs-1.c, gcc.dg/init-desig-obs-2.c,
+ gcc.dg/init-desig-obs-3.c: New tests.
+
2004-10-25 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/debug/20041023-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/init-desig-obs-1.c b/gcc/testsuite/gcc.dg/init-desig-obs-1.c
new file mode 100644
index 00000000000..4a9df0482b8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/init-desig-obs-1.c
@@ -0,0 +1,19 @@
+/* Test obsolete forms of designated initializers. Test with default
+ warning options: valid forms are accepted, while ".member" without
+ "=" should not be (bug 16667). */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+struct s { int a; };
+struct s s0 = { .a = 1 };
+struct s s1 = { a: 1 };
+
+int x0[] = { [0] = 1 };
+int x1[] = { [0] 1 };
+
+/* Invalid syntax: multiple designators without "=". */
+int x2[2][2] = { [0][0] 1 }; /* { dg-error "(syntax|parse) error" } */
+
+
+/* Invalid syntax: C99-style structure designator without "=". */
+struct s s2 = { .a 1 }; /* { dg-error "(syntax|parse) error" } */
diff --git a/gcc/testsuite/gcc.dg/init-desig-obs-2.c b/gcc/testsuite/gcc.dg/init-desig-obs-2.c
new file mode 100644
index 00000000000..04c3b1048e8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/init-desig-obs-2.c
@@ -0,0 +1,11 @@
+/* Test obsolete forms of designated initializers. Test with
+ -pedantic. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic" } */
+struct s { int a; };
+struct s s0 = { .a = 1 };
+struct s s1 = { a: 1 }; /* { dg-warning "warning: obsolete use of designated initializer with ':'" } */
+
+int x0[] = { [0] = 1 };
+int x1[] = { [0] 1 }; /* { dg-warning "warning: obsolete use of designated initializer without '='" } */
diff --git a/gcc/testsuite/gcc.dg/init-desig-obs-3.c b/gcc/testsuite/gcc.dg/init-desig-obs-3.c
new file mode 100644
index 00000000000..9cc50ba3373
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/init-desig-obs-3.c
@@ -0,0 +1,11 @@
+/* Test obsolete forms of designated initializers. Test with
+ -pedantic-errors. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
+struct s { int a; };
+struct s s0 = { .a = 1 };
+struct s s1 = { a: 1 }; /* { dg-error "error: obsolete use of designated initializer with ':'" } */
+
+int x0[] = { [0] = 1 };
+int x1[] = { [0] 1 }; /* { dg-error "error: obsolete use of designated initializer without '='" } */