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]
Other format: [Raw text]

Re: [PATCH, C++] Fix pr43779


On 04/29/2010 06:22 PM, Gabriel Dos Reis wrote:
On Thu, Apr 29, 2010 at 2:54 AM, Shujing Zhao <pearly.zhao@oracle.com> wrote:
On 04/28/2010 06:49 PM, Manuel LÃpez-IbÃÅez wrote:
On 28 April 2010 12:48, Manuel LÃpez-IbÃÅez <lopezibanez@gmail.com> wrote:
On 28 April 2010 12:01, Shujing Zhao <pearly.zhao@oracle.com> wrote:
Hi,

This patch fixed pr43779 that emits the diagnostic for easy translation.
Tested on i686-pc-linux-gnu with no regression. OK for trunk?
Since it is reported for 4.5.0, should gcc-4_5-branch be fixed too?
Being picky, a static function that abstracts out this code with a
boolean for fewer/too many will be shorter (check the boolean last to
choose the appropriate string), and make the original function shorter
as well.
In fact, that the function takes a location parameter would be even
better, so when we get the correct location, only the calls need to be
updated.

 error_at (loc,
            (too_many_p)
            ? _("too many arguments to constructor %q#D")
            : _("too few arguments to constructor %q#D"),
          fndecl);

Manuel, thanks for the reply.
The updated patch is add a static function warn_args_num to print the
diagnostics. Tested on i686-pc-linux-gnu and no regression.

Is it ok?

Make sure you follow the GCC coding standard for the ternary operator " ? : " when the arguments spans multiple lines. OK.
Ok. Fix the problems and Retested.
Change

+           error_at (loc, too_many_p
+                     ? G_("too many arguments to constructor %q#D")
+                     : G_("too few arguments to constructor %q#D"),

to

+           error_at (loc,
+                     too_many_p
+                     ? G_("too many arguments to constructor %q#D")
+                     : G_("too few arguments to constructor %q#D"),

Change
+           warn_args_num (input_location, fndecl, true /* too_manay_p */);
to
+           warn_args_num (input_location, fndecl, /*too_many_p=*/true);

Change
+    error (too_many_p ? G_("too many arguments to function")
to
+    error_at (loc, too_many_p ? G_("too many arguments to function")

Is it ok?

Thanks
Pearly


Index: typeck.c
===================================================================
--- typeck.c	(revision 158822)
+++ typeck.c	(working copy)
@@ -61,6 +61,7 @@ static void casts_away_constness_r (tree
 static bool casts_away_constness (tree, tree);
 static void maybe_warn_about_returning_address_of_local (tree);
 static tree lookup_destructor (tree, tree, tree);
+static void warn_args_num (location_t, tree, bool);
 static int convert_arguments (tree, VEC(tree,gc) **, tree, int,
                               tsubst_flags_t);
 
@@ -3286,6 +3287,44 @@ cp_build_function_call_vec (tree functio
   return ret;
 }
 
+/* Subroutine of convert_arguments.
+   Warn about wrong number of args are genereted. */
+
+static void
+warn_args_num (location_t loc, tree fndecl, bool too_many_p)
+{
+  if (fndecl)
+    {
+      if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
+	{
+	  if (DECL_NAME (fndecl) == NULL_TREE
+	      || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl)))
+	    error_at (loc,
+		      too_many_p
+		      ? G_("too many arguments to constructor %q#D")
+		      : G_("too few arguments to constructor %q#D"),
+		      fndecl);
+	  else
+	    error_at (loc,
+		      too_many_p
+		      ? G_("too many arguments to member function %q#D")
+		      : G_("too few arguments to member function %q#D"),
+		      fndecl);
+	}
+      else
+	error_at (loc,
+		  too_many_p
+		  ? G_("too many arguments to function %q#D")
+		  : G_("too few arguments to function %q#D"),
+		  fndecl);
+      inform (DECL_SOURCE_LOCATION (fndecl),
+	      "declared here");
+    }
+  else
+    error_at (loc, too_many_p ? G_("too many arguments to function")
+		      	      : G_("too few arguments to function"));
+}
+
 /* Convert the actual parameter expressions in the list VALUES to the
    types in the list TYPELIST.  The converted expressions are stored
    back in the VALUES vector.
@@ -3307,26 +3346,11 @@ convert_arguments (tree typelist, VEC(tr
 		   int flags, tsubst_flags_t complain)
 {
   tree typetail;
-  const char *called_thing = 0;
   unsigned int i;
 
   /* Argument passing is always copy-initialization.  */
   flags |= LOOKUP_ONLYCONVERTING;
 
-  if (fndecl)
-    {
-      if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
-	{
-	  if (DECL_NAME (fndecl) == NULL_TREE
-	      || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl)))
-	    called_thing = "constructor";
-	  else
-	    called_thing = "member function";
-	}
-      else
-	called_thing = "function";
-    }
-
   for (i = 0, typetail = typelist;
        i < VEC_length (tree, *values);
        i++)
@@ -3341,15 +3365,7 @@ convert_arguments (tree typelist, VEC(tr
 	{
           if (complain & tf_error)
             {
-              if (fndecl)
-                {
-                  error_at (input_location, "too many arguments to %s %q#D", 
-			    called_thing, fndecl);
-		  inform (DECL_SOURCE_LOCATION (fndecl),
-			  "declared here");
-                }
-              else
-                error ("too many arguments to function");
+	      warn_args_num (input_location, fndecl, /*too_many_p=*/true);
               return i;
             }
           else
@@ -3454,17 +3470,7 @@ convert_arguments (tree typelist, VEC(tr
       else
 	{
           if (complain & tf_error)
-            {
-              if (fndecl)
-                {
-                  error_at (input_location, "too few arguments to %s %q#D", 
-			    called_thing, fndecl);
-		  inform (DECL_SOURCE_LOCATION (fndecl),
-			  "declared here");
-                }
-              else
-                error ("too few arguments to function");
-            }
+	    warn_args_num (input_location, fndecl, /*too_many_p=*/false);
 	  return -1;
 	}
     }

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