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]

Patch for c/166


This patch fixes PR c/166 (failure to parse redeclaration of a typedef
name as a parameter in certain cases).  Testcase
gcc.c-torture/compile/20010114-1.c.

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

2001-05-19  Joseph S. Myers  <jsm28@cam.ac.uk>

	* c-parse.in (parm_declarator): Split into
	parm_declarator_starttypename and parm_declarator_nostarttypename.
	(parm_declarator_starttypename, parm_declarator_nostarttypename):
	New.  Allow parenthesised sub-declarators which don't begin with a
	TYPENAME.  Fixes PR c/166.

testsuite:
2001-05-19  Joseph S. Myers  <jsm28@cam.ac.uk>

	* gcc.c-torture/compile/20010114-1.x: Remove.

--- c-parse.in.orig	Sun May 13 10:50:08 2001
+++ c-parse.in	Sun May 13 11:49:03 2001
@@ -197,6 +197,7 @@
 %type <ttype> declarator
 %type <ttype> notype_declarator after_type_declarator
 %type <ttype> parm_declarator
+%type <ttype> parm_declarator_starttypename parm_declarator_nostarttypename
 
 %type <ttype> structsp_attr structsp_nonattr
 %type <ttype> component_decl_list component_decl_list2
@@ -1682,27 +1683,54 @@
    in addition to notype_declarator.  This is like after_type_declarator
    but does not allow a typedef name in parentheses as an identifier
    (because it would conflict with a function with that typedef as arg).  */
-
 parm_declarator:
-	  parm_declarator '(' parmlist_or_identifiers  %prec '.'
+	  parm_declarator_starttypename
+	| parm_declarator_nostarttypename
+	;
+
+parm_declarator_starttypename:
+	  parm_declarator_starttypename '(' parmlist_or_identifiers  %prec '.'
 		{ $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
-/*	| parm_declarator '(' error ')'  %prec '.'
+/*	| parm_declarator_starttypename '(' error ')'  %prec '.'
 		{ $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
 		  poplevel (0, 0, 0); }  */
 ifc
-	| parm_declarator '[' '*' ']'  %prec '.'
+	| parm_declarator_starttypename '[' '*' ']'  %prec '.'
 		{ $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
 		  if (! flag_isoc99)
 		    error ("`[*]' in parameter declaration only allowed in ISO C 99");
 		}
 end ifc
-	| parm_declarator '[' expr ']'  %prec '.'
+	| parm_declarator_starttypename '[' expr ']'  %prec '.'
 		{ $$ = build_nt (ARRAY_REF, $1, $3); }
-	| parm_declarator '[' ']'  %prec '.'
+	| parm_declarator_starttypename '[' ']'  %prec '.'
 		{ $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
-	| '*' maybe_type_quals_setattrs parm_declarator  %prec UNARY
-		{ $$ = make_pointer_declarator ($2, $3); }
 	| TYPENAME
+	;
+
+parm_declarator_nostarttypename:
+	  parm_declarator_nostarttypename '(' parmlist_or_identifiers  %prec '.'
+		{ $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
+/*	| parm_declarator_nostarttypename '(' error ')'  %prec '.'
+		{ $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
+		  poplevel (0, 0, 0); }  */
+ifc
+	| parm_declarator_nostarttypename '[' '*' ']'  %prec '.'
+		{ $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
+		  if (! flag_isoc99)
+		    error ("`[*]' in parameter declaration only allowed in ISO C 99");
+		}
+end ifc
+	| parm_declarator_nostarttypename '[' expr ']'  %prec '.'
+		{ $$ = build_nt (ARRAY_REF, $1, $3); }
+	| parm_declarator_nostarttypename '[' ']'  %prec '.'
+		{ $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
+	| '*' maybe_type_quals_setattrs parm_declarator_starttypename  %prec UNARY
+		{ $$ = make_pointer_declarator ($2, $3); }
+	| '*' maybe_type_quals_setattrs parm_declarator_nostarttypename  %prec UNARY
+		{ $$ = make_pointer_declarator ($2, $3); }
+	| '(' maybe_setattrs parm_declarator_nostarttypename ')'
+		{ $$ = $3; }
 	;
 
 /* A declarator allowed whether or not there has been
--- testsuite/gcc.c-torture/compile/20010114-1.x.orig	Sun Jan 14 00:09:49 2001
+++ testsuite/gcc.c-torture/compile/20010114-1.x	Mon Mar 26 23:57:02 2001
@@ -1,2 +0,0 @@
-set torture_compile_xfail "*-*-*"
-return 0

-- 
Joseph S. Myers
jsm28@cam.ac.uk


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