Help w/-Wtraditional warning about ISO C style function definitions

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Thu Mar 7 13:28:00 GMT 2002


 > From: Neil Booth <neil@daikokuya.demon.co.uk>
 > 
 > Kaveh R. Ghazi wrote:-
 > 
 > > I was wondering if there was an easy way to determine when we reach the code
 > > below whether we are in the midst of parsing a function definition,
 > > possibly by examining `current_declspecs' or something similar.
 > > 
 > > Thanks in advance for any help.
 > 
 > No, you can't tell until you see a ';' or '{' later.  This is the cause
 > of other issues in the C front end, e.g. with -Wshadow.
 > Neil.


Ok, then I suppose I'll have to keep state.  This seems to work
properly, are there any obvious problems with this approach?

If not, I'll proceed to add docs and a testcase and submit it.

		Thanks,
		--Kaveh


--- ../../orig/egcc-CVS20020305/gcc/c-parse.in	Thu Feb 28 15:41:41 2002
+++ ../../egcc-CVS20020305/gcc/c-parse.in	Thu Mar  7 16:20:43 2002
@@ -293,6 +293,8 @@ ifc
 #define OBJC_NEED_RAW_IDENTIFIER(VAL)	/* nothing */
 end ifc
 
+static bool parsing_iso_function_signature;
+
 /* Tell yyparse how to print a token's value, if yydebug is set.  */
 
 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
@@ -349,7 +351,9 @@ extdefs:
 
 extdef:
 	fndef
+	{ parsing_iso_function_signature = false; } /* Reset after a definition */
 	| datadef
+	{ parsing_iso_function_signature = false; } /* Reset after a declaration */
 ifobjc
 	| objcdef
 end ifobjc
@@ -771,6 +775,13 @@ objc_string:
 end ifobjc
 
 old_style_parm_decls:
+	{
+	  if (warn_traditional && parsing_iso_function_signature)
+	    warning ("traditional C rejects ISO C style function definitions[3]");
+	}
+	old_style_parm_decls_1
+
+old_style_parm_decls_1:
 	/* empty */
 	| datadecls
 	| datadecls ELLIPSIS
@@ -2524,7 +2535,9 @@ parmlist_2:  /* empty */
 		  error ("ISO C requires a named argument before `...'");
 		}
 	| parms
-		{ $$ = get_parm_info (1); }
+		{ $$ = get_parm_info (1);
+		  parsing_iso_function_signature = true;
+		}
 	| parms ',' ELLIPSIS
 		{ $$ = get_parm_info (0); }
 	;



More information about the Gcc-patches mailing list