This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch for PR 11943


This patch fixes PR c/11943, where array declarators were accepted
with a compound expression when the syntax in C99 says
assignment-expression.  (In C90 the syntax says constant-expression
and all the invalid cases should already be caught - provided
-pedantic is given - on account of the expressions not being
constant.)

Bootstrapped with no regressions on i686-pc-linux-gnu.  Applied to
mainline.

2003-10-24  Joseph S. Myers  <jsm@polyomino.org.uk>

	* c-parse.in (array_declarator): Use expr_no_commas.
	Fixes PR c/11943.

2003-10-24  Joseph S. Myers  <jsm@polyomino.org.uk>

	* gcc.dg/c99-arraydecl-2.c: New test.  PR c/11943.

--- GCC/gcc/c-parse.in.orig	2003-10-15 08:05:45.000000000 +0000
+++ GCC/gcc/c-parse.in	2003-10-24 09:04:47.000000000 +0000
@@ -1973,16 +1973,16 @@
 /* The [...] part of a declarator for an array type.  */
 
 array_declarator:
-	'[' maybe_type_quals_attrs expr ']'
+	'[' maybe_type_quals_attrs expr_no_commas ']'
 		{ $$ = build_array_declarator ($3, $2, 0, 0); }
 	| '[' maybe_type_quals_attrs ']'
 		{ $$ = build_array_declarator (NULL_TREE, $2, 0, 0); }
 	| '[' maybe_type_quals_attrs '*' ']'
 		{ $$ = build_array_declarator (NULL_TREE, $2, 0, 1); }
-	| '[' STATIC maybe_type_quals_attrs expr ']'
+	| '[' STATIC maybe_type_quals_attrs expr_no_commas ']'
 		{ $$ = build_array_declarator ($4, $3, 1, 0); }
 	/* declspecs_nosc_nots is a synonym for type_quals_attrs.  */
-	| '[' declspecs_nosc_nots STATIC expr ']'
+	| '[' declspecs_nosc_nots STATIC expr_no_commas ']'
 		{ $$ = build_array_declarator ($4, $2, 1, 0); }
 	;
 
--- GCC/gcc/testsuite/gcc.dg/c99-arraydecl-2.c	2002-08-26 16:21:36.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/c99-arraydecl-2.c	2003-10-24 09:11:39.000000000 +0000
@@ -0,0 +1,16 @@
+/* Test for C99 array declarators: expression must be an
+   assignment-expression.  PR 11943.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+void
+foo (void)
+{
+  int a[2, 3]; /* { dg-error "parse|syntax" "bad array declarator" } */
+  void b(int x[2, 3]); /* { dg-error "parse|syntax" "bad array declarator" } */
+  void c(int [2, 3]); /* { dg-error "parse|syntax" "bad array declarator" } */
+  void d(int *x[restrict 2, 3]); /* { dg-error "parse|syntax" "bad array declarator" } */
+  void e(int *x[static restrict 2, 3]); /* { dg-error "parse|syntax" "bad array declarator" } */
+  void f(int *x[restrict static 2, 3]); /* { dg-error "parse|syntax" "bad array declarator" } */
+}

-- 
Joseph S. Myers
jsm@polyomino.org.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]