Patch -Wtraditional, numeric constant suffix warnings (take 2)

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Wed Aug 9 13:32:00 GMT 2000


Thanks to all of you who responded last time.

Based on the feedback, I've left out warnings about the integer `L'
modifier, but I've updated the patch to additionally warn about the
`F' and `L' floating point suffixes.  I only did that for cc1, since
cpp seems to already reject floats in #if conditionals.  I also added
documentation in invoke.texi.

I'm not entirely happy that we get warnings about uses of UINT_MAX,
etc, in user code.  But its not a lot.  E.g. we get 14 in a solaris
bootstrap.  Ten are from one line in gettext.h.  Two occur in loop.c
and two in cpplex.c.  So I think its manageable.

Zack regarding your suggestion of extending cpp to mark where macros
were defined and elide these if the macro came from a system header,
is that something a non-cpplib expert can do quickly or is it very
involved?  (The other option is to simply not teach cpp about this
warning.)

Anyway, this patch was bootstrapped on solaris2.7, okay to install?

		Thanks,
		--Kaveh



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

	* c-lex.c (parse_float, yylex): For -Wtraditional, issue a
	warning about non-traditional numeric constant suffixes.

	* cppexp.c (parse_number): Likewise.

	* invoke.texi: (-Wtraditional): Document new behavior.

diff -rup orig/egcs-CVS20000808/gcc/c-lex.c egcs-CVS20000808/gcc/c-lex.c
--- orig/egcs-CVS20000808/gcc/c-lex.c	Tue Aug  8 21:17:21 2000
+++ egcs-CVS20000808/gcc/c-lex.c	Wed Aug  9 13:20:53 2000
@@ -1109,12 +1109,16 @@ parse_float (data)
 	case 'f': case 'F':
 	  if (fflag)
 	    error ("more than one `f' in numeric constant");
+	  else if (warn_traditional && !in_system_header)
+	    warning ("traditional C rejects the `%c' suffix", args->c);
 	  fflag = 1;
 	  break;
 
 	case 'l': case 'L':
 	  if (lflag)
 	    error ("more than one `l' in numeric constant");
+	  else if (warn_traditional && !in_system_header)
+	    warning ("traditional C rejects the `%c' suffix", args->c);
 	  lflag = 1;
 	  break;
 
@@ -1773,6 +1777,8 @@ yylex ()
 		  {
 		    if (spec_unsigned)
 		      error ("two `u's in integer constant");
+ 		    else if (warn_traditional && !in_system_header)
+ 		      warning ("traditional C rejects the `%c' suffix", c);
 		    spec_unsigned = 1;
 		    if (spec_long)
 		      suffix_lu = 1;
diff -rup orig/egcs-CVS20000808/gcc/cppexp.c egcs-CVS20000808/gcc/cppexp.c
--- orig/egcs-CVS20000808/gcc/cppexp.c	Wed Aug  2 10:20:18 2000
+++ egcs-CVS20000808/gcc/cppexp.c	Wed Aug  9 13:09:43 2000
@@ -218,6 +218,8 @@ parse_number (pfile, tok)
 	goto invalid_suffix;
       op.unsignedp = sufftab[i].u;
 
+      if (CPP_WTRADITIONAL (pfile) && sufftab[i].u)
+	cpp_warning (pfile, "traditional C rejects the `U' suffix");
       if (CPP_OPTION (pfile, c89) && sufftab[i].l == 2)
 	SYNTAX_ERROR ("too many 'l' suffixes in integer constant");
     }
diff -rup orig/egcs-CVS20000808/gcc/invoke.texi egcs-CVS20000808/gcc/invoke.texi
--- orig/egcs-CVS20000808/gcc/invoke.texi	Mon Aug  7 10:11:22 2000
+++ egcs-CVS20000808/gcc/invoke.texi	Wed Aug  9 13:37:23 2000
@@ -1831,6 +1831,15 @@ Initialization of automatic aggregates.
 @item
 Identifier conflicts with labels.  Traditional C lacks a separate
 namespace for labels.
+
+@item
+The `U' integer constant suffix, or the `F' or `L' floating point
+constant suffixes.  (Traditonal C does support the `L' suffix on integer
+constants.)  Note, these suffixes appear in macros defined in the system
+headers of most modern systems, e.g. the _MIN/_MAX macros in limits.h.
+Use of these macros can lead to spurious warnings as they do not
+necessarily reflect whether the code in question is any less portable to
+traditional C given that suitable backup definitions are provided.
 @end itemize
 
 @item -Wundef


More information about the Gcc-patches mailing list