* Patch for bug 16667
@ 2004-10-25 22:44 Joseph S. Myers
0 siblings, 0 replies; only message in thread
From: Joseph S. Myers @ 2004-10-25 22:44 UTC (permalink / raw)
To: gcc-patches
This patch fixes bug 16667, reporting that an undocumented hybrid form
of old GNU-style designated initializers and C99-style designated
initializers, ".foo" field designators without "=", was wrongly
accepted. I've of course made a corresponding change to my new
parser. This saves adding testcases that this hybrid form is accepted
when writing/generating tests that the new and old parsers accept the
same language.
Since this hybrid form was never documented, having been added
accidentally by Drepper's patch
<http://gcc.gnu.org/ml/gcc-patches/1998-11/msg00302.html> (committed
version: <http://gcc.gnu.org/ml/gcc-patches/1998-12/msg00001.html>), I
consider it safe to remove as a bug fix rather than requiring a
deprecation period as would properly deprecating all uses of old-style
designated initializers.
Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to
mainline.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
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 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.
diff -rupN GCC.orig/gcc/c-parse.in GCC/gcc/c-parse.in
--- GCC.orig/gcc/c-parse.in 2004-10-19 19:40:51.000000000 +0000
+++ GCC/gcc/c-parse.in 2004-10-25 13:03:51.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/init-desig-obs-1.c GCC/gcc/testsuite/gcc.dg/init-desig-obs-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/init-desig-obs-1.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/init-desig-obs-1.c 2004-10-25 12:58:53.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/init-desig-obs-2.c GCC/gcc/testsuite/gcc.dg/init-desig-obs-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/init-desig-obs-2.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/init-desig-obs-2.c 2004-10-25 13:00:16.000000000 +0000
@@ -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 -rupN GCC.orig/gcc/testsuite/gcc.dg/init-desig-obs-3.c GCC/gcc/testsuite/gcc.dg/init-desig-obs-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/init-desig-obs-3.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/init-desig-obs-3.c 2004-10-25 13:00:34.000000000 +0000
@@ -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 '='" } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-10-25 22:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-25 22:44 Patch for bug 16667 Joseph S. Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).