Commit 535dd320 by Joseph Myers Committed by Joseph Myers

re PR c/16667 (GCC allows invalid syntax in C99 designated initializers)

	PR c/16667
	* c-parse.in (array_designator): New.
	(designator): Use it.
	(initelt): Only permit array_designator without '=', not ".foo".

testsuite:
	* gcc.dg/init-desig-obs-1.c, gcc.dg/init-desig-obs-2.c,
	gcc.dg/init-desig-obs-3.c: New tests.

From-SVN: r89560
parent 85c33455
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> 2004-10-25 Kenneth Zadeck <zadeck@naturalbridge.com>
* gcc/Makefile.in: removed ggc for cgraphunit. * gcc/Makefile.in: removed ggc for cgraphunit.
* gcc/cgraph.c.dump_cgraph_node: removed static var analysis. * gcc/cgraph.c.dump_cgraph_node: removed static var analysis.
......
...@@ -1445,7 +1445,7 @@ initelt: ...@@ -1445,7 +1445,7 @@ initelt:
designator_list '=' initval designator_list '=' initval
{ if (pedantic && !flag_isoc99) { if (pedantic && !flag_isoc99)
pedwarn ("ISO C90 forbids specifying subobject to initialize"); } pedwarn ("ISO C90 forbids specifying subobject to initialize"); }
| designator initval | array_designator initval
{ if (pedantic) { if (pedantic)
pedwarn ("obsolete use of designated initializer without %<=%>"); } pedwarn ("obsolete use of designated initializer without %<=%>"); }
| identifier ':' | identifier ':'
...@@ -1475,7 +1475,10 @@ designator_list: ...@@ -1475,7 +1475,10 @@ designator_list:
designator: designator:
'.' identifier '.' identifier
{ set_init_label ($2); } { 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); { set_init_index ($2.value, $4.value);
if (pedantic) if (pedantic)
pedwarn ("ISO C forbids specifying range of elements to initialize"); } pedwarn ("ISO C forbids specifying range of elements to initialize"); }
......
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> 2004-10-25 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/debug/20041023-1.c: New test. * gcc.dg/debug/20041023-1.c: New test.
......
/* 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" } */
/* 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 '='" } */
/* 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 '='" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment