Patch to fix diagnostic format warnings in cp/ dir

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Mon Jun 30 16:21:00 GMT 2003


This patch zaps the diagnostic format warnings in the cp/ directory.
Some of the warnings are bugs from extra or missing parameters.

However the cp_*_at functions do something quite evil IMO.  They allow
something like this:

 > cp_error_at ("no specifiers", extra_arg);

I.e. they allow an extra trailing argument and the line number
location info is sucked out of the extra argument.  This is
incompatible with GCC's kind of format checking.  So in those few
cases I added an explicit specifier to consume the argument containing
the line number info.  This will cause the message to be slightly more
verbose, but IMHO that's just fine.

Bootstrapped on sparc-sun-solaris2.7 (minus java), no regressions.

However I'm not sure if the C++ testsuite triggers all of these
messages and my C++ isn't robust enough to write testcases to do so
either.  So while the format checker says they're all ok, I'd
appreciate another pair of eyes on the text message changes.

Ok for mainline?

                Thanks!
                --Kaveh


2003-06-20  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* class.c (add_method, check_field_decl): Fix format specifier.
	* decl.c (duplicate_decls, pushdecl, check_goto,
	fixup_anonymous_aggr, maybe_commonize_var, grokdeclarator,
	start_enum): Likewise.
	* decl2.c (ambiguous_decl): Likewise.
	* pt.c (redeclare_class_template): Likewise.

diff -rup orig/egcc-CVS20030628/gcc/cp/class.c egcc-CVS20030628/gcc/cp/class.c
--- orig/egcc-CVS20030628/gcc/cp/class.c	2003-06-24 12:16:35.000000000 -0400
+++ egcc-CVS20030628/gcc/cp/class.c	2003-06-29 00:02:39.159019717 -0400
@@ -927,7 +927,7 @@ add_method (tree type, tree method, int 
 	      else
 		{
 		  cp_error_at ("`%#D' and `%#D' cannot be overloaded",
-			       method, fn, method);
+			       method, fn);
 
 		  /* We don't call duplicate_decls here to merge
 		     the declarations because that will confuse
@@ -2961,7 +2961,7 @@ check_field_decl (tree field,
       /* `build_class_init_list' does not recognize
 	 non-FIELD_DECLs.  */
       if (TREE_CODE (t) == UNION_TYPE && any_default_members != 0)
-	cp_error_at ("multiple fields in union `%T' initialized");
+	cp_error_at ("multiple fields in union `%T' initialized", t);
       *any_default_members = 1;
     }
 }
diff -rup orig/egcc-CVS20030628/gcc/cp/decl.c egcc-CVS20030628/gcc/cp/decl.c
--- orig/egcc-CVS20030628/gcc/cp/decl.c	2003-06-28 20:01:23.000000000 -0400
+++ egcc-CVS20030628/gcc/cp/decl.c	2003-06-29 00:02:39.199022706 -0400
@@ -3134,7 +3134,7 @@ duplicate_decls (tree newdecl, tree oldd
 	{
 	  /* Prototype decl follows defn w/o prototype.  */
 	  cp_warning_at ("prototype for `%#D'", newdecl);
-	  cp_warning_at ("follows non-prototype definition here", olddecl);
+	  cp_warning_at ("follows non-prototype definition for `%#D' here", olddecl);
 	}
       else if (TREE_CODE (olddecl) == FUNCTION_DECL
 	       && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
@@ -3191,7 +3191,7 @@ duplicate_decls (tree newdecl, tree oldd
 	    {
 	      warning ("`%#D' was used before it was declared inline",
 			  newdecl);
-	      cp_warning_at ("previous non-inline declaration here",
+	      cp_warning_at ("previous non-inline declaration for `%#D' here",
 			     olddecl);
 	    }
 	}
@@ -3884,7 +3884,7 @@ pushdecl (tree x)
 	      && TREE_CODE (decl) == TREE_CODE (x)
 	      && !same_type_p (TREE_TYPE (x), TREE_TYPE (decl)))
 	    {
-	      pedwarn ("type mismatch with previous external decl", x);
+	      pedwarn ("type mismatch with previous external decl of `%#D'", x);
 	      cp_pedwarn_at ("previous external decl of `%#D'", decl);
 	    }
 	}
@@ -4921,7 +4921,7 @@ check_goto (tree decl)
 
       if (u > 1 && DECL_ARTIFICIAL (b))
 	/* Can't skip init of __exception_info.  */
-	cp_error_at ("  enters catch block", b);
+	cp_error_at ("  enters catch block `%#D'", b);
       else if (u > 1)
 	cp_error_at ("  skips initialization of `%#D'", b);
       else
@@ -6689,7 +6689,7 @@ fixup_anonymous_aggr (tree t)
 
   /* ISO C++ 9.5.3.  Anonymous unions may not have function members.  */
   if (TYPE_METHODS (t))
-    cp_error_at ("an anonymous union cannot have function members", t);
+    cp_error_at ("an anonymous union `%T' cannot have function members", t);
 
   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
      assignment operators (because they cannot have these methods themselves).
@@ -7390,7 +7390,7 @@ maybe_commonize_var (tree decl)
 	      TREE_PUBLIC (decl) = 0;
 	      DECL_COMMON (decl) = 0;
 	      cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl);
-	      cp_warning_at ("  you can work around this by removing the initializer", decl);
+	      cp_warning_at ("  you can work around this by removing the initializer for `%D'", decl);
 	    }
 	}
     }
@@ -11137,7 +11137,7 @@ grokdeclarator (tree declarator,
 	{
 	  decl = build_decl (TYPE_DECL, declarator, type);
 	  if (in_namespace || ctype)
-	    cp_error_at ("typedef name may not be a nested-name-specifier",
+	    cp_error_at ("typedef name for `%#D' may not be a nested-name-specifier",
 			 decl);
 	  if (!current_function_decl)
 	    DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
@@ -11184,7 +11184,7 @@ grokdeclarator (tree declarator,
 	  if (ctype == NULL_TREE)
 	    {
 	      if (TREE_CODE (type) != METHOD_TYPE)
-		cp_error_at ("invalid type qualifier for non-member function type", decl);
+		cp_error_at ("invalid type qualifier for non-member function type `%#D'", decl);
 	      else
 		ctype = TYPE_METHOD_BASETYPE (type);
 	    }
@@ -13011,7 +13011,7 @@ start_enum (tree name)
   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
     {
       error ("multiple definition of `%#T'", enumtype);
-      cp_error_at ("previous definition here", enumtype);
+      cp_error_at ("previous definition of `%T' here", enumtype);
       /* Clear out TYPE_VALUES, and start again.  */
       TYPE_VALUES (enumtype) = NULL_TREE;
     }
diff -rup orig/egcc-CVS20030628/gcc/cp/decl2.c egcc-CVS20030628/gcc/cp/decl2.c
--- orig/egcc-CVS20030628/gcc/cp/decl2.c	2003-06-24 12:16:36.000000000 -0400
+++ egcc-CVS20030628/gcc/cp/decl2.c	2003-06-29 00:02:39.209019119 -0400
@@ -3643,8 +3643,8 @@ ambiguous_decl (tree name, cxx_binding *
       if (flags & LOOKUP_COMPLAIN)
         {
           error ("`%D' denotes an ambiguous type",name);
-          cp_error_at ("  first type here", BINDING_TYPE (old));
-          cp_error_at ("  other type here", type);
+          cp_error_at ("  first type `%T' here", BINDING_TYPE (old));
+          cp_error_at ("  other type `%T' here", type);
         }
     }
   return old;
diff -rup orig/egcc-CVS20030628/gcc/cp/pt.c egcc-CVS20030628/gcc/cp/pt.c
--- orig/egcc-CVS20030628/gcc/cp/pt.c	2003-06-28 20:01:25.000000000 -0400
+++ egcc-CVS20030628/gcc/cp/pt.c	2003-06-29 00:02:39.239019128 -0400
@@ -2984,7 +2984,7 @@ redeclare_class_template (tree type, tre
 	     A template-parameter may not be given default arguments
 	     by two different declarations in the same scope.  */
 	  error ("redefinition of default argument for `%#D'", parm);
-	  cp_error_at ("  original definition appeared here", tmpl_parm);
+	  cp_error_at ("  original definition of `%#D' appeared here", tmpl_parm);
 	  return;
 	}
 



More information about the Gcc-patches mailing list