Patch: avoid prototype warnings for SIG_DFL defined as (void(*)())0

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Mon Jul 17 11:02:00 GMT 2000


We're getting -Wstrict-prototype warnings on some platforms when we
use the SIG_* macros from signal.h.  This is because they are defined
like so: "#define SIG_DFL (void(*)())0".

Although -Wstrict-prototype doesn't warn about system header problems,
this cast isn't elided because while the macro itself is defined in a
system header, its use occurs in user code.

One might initially suggest using fixincl to insert the proper
argument into the macro definition in the header file, and in fact I
believe fixinc.svr4 does this.  However on a platform like Solaris2
where we use the "wrap" fixes, we don't want to muck with system
headers to prototype the macro casts.

So instead I taught -Wstrict-prototypes not to warn about prototypes
in type casts when the subject of the cast is an INTEGER_CST.

Bootstrapped on Solaris2.7, ~30 bogus prototype warnings are eliminated.

Okay to install?

		--Kaveh



2000-07-17  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* c-parse.in (cast_expr): Avoid -Wstrict-prototype warnings for
	unprototyped function pointer casts on integer constants.

diff -rup orig/egcs-CVS20000716/gcc/c-parse.in egcs-CVS20000716/gcc/c-parse.in
--- orig/egcs-CVS20000716/gcc/c-parse.in	Wed Jul 12 15:51:19 2000
+++ egcs-CVS20000716/gcc/c-parse.in	Mon Jul 17 10:35:22 2000
@@ -518,7 +518,14 @@ alignof:
 cast_expr:
 	unary_expr
 	| '(' typename ')' cast_expr  %prec UNARY
-		{ tree type = groktypename ($2);
+		{ tree type;
+		  int SAVED_warn_strict_prototypes = warn_strict_prototypes;
+		  /* This avoids warnings about unprototyped casts on
+                     integers.  E.g. "#define SIG_DFL (void(*)())0".  */
+		  if (TREE_CODE ($4) == INTEGER_CST)
+		    warn_strict_prototypes = 0;
+		  type = groktypename ($2);
+		  warn_strict_prototypes = SAVED_warn_strict_prototypes;
 		  $$ = build_c_cast (type, $4); }
 	| '(' typename ')' '{' 
 		{ start_init (NULL_TREE, NULL, 0);


More information about the Gcc-patches mailing list