diff mbox

ObjC/ObjC++: fixed 'too many arguments to method xxx' error

Message ID 1284264562.32429259@192.168.2.227
State New
Headers show

Commit Message

Nicola Pero Sept. 12, 2010, 4:09 a.m. UTC
I took the testcase (marked as Apple Radar 4491608) from the 

  gcc.gnu.org/svn/gcc/branches/apple/trunk

branch (the one on the FSF servers that was agreed to be OK to merge from).

The problem is that calling an Objective-C method with too many arguments would return the vague error 'too many arguments to function', with no mention of what problematic method was.

The branch had a working one-liner fix, but I didn't particularly like it because it only added the name of the method, but the error message still called it a 'function' instead of a 'method', and there was no fix for ObjC++.

Below a more satisfactory patch by myself, with an additional Objective-C++ test.  OK to commit to trunk ?

Thanks

Comments

Joseph Myers Sept. 12, 2010, 12:53 p.m. UTC | #1
On Sun, 12 Sep 2010, Nicola Pero wrote:

> Below a more satisfactory patch by myself, with an additional 
> Objective-C++ test.  OK to commit to trunk ?

Please include the ChangeLog entries with patch submissions and generate 
diffs with "-p".  You did neither, so your patch does not usefully 
indicate what functions are being changed.
Mike Stump Sept. 12, 2010, 7:38 p.m. UTC | #2
On Sep 11, 2010, at 9:09 PM, Nicola Pero wrote:
> I took the testcase (marked as Apple Radar 4491608) from the 
> 
>  gcc.gnu.org/svn/gcc/branches/apple/trunk

In general, I'll pre-approve the gcc/objc subdirectory changes from that branch and the corresponding objc testsuite changes as well.

> OK to commit to trunk ?

The testsuite/objc.* changes are ok once the corresponding FE bits are approved.
diff mbox

Patch

Index: testsuite/objc.dg/too-many-args.m
===================================================================
--- testsuite/objc.dg/too-many-args.m   (revision 0)
+++ testsuite/objc.dg/too-many-args.m   (revision 0)
@@ -0,0 +1,10 @@ 
+/* { dg-do compile } */
+
+@interface SomeClass
++ method:(int)foo;
+@end
+
+int main(void) {
+    [SomeClass method:3, 4];   /* { dg-error "too many arguments to method \\'method:\\'" } */
+    return 0;
+}
Index: testsuite/obj-c++.dg/too-many-args.mm
===================================================================
--- testsuite/obj-c++.dg/too-many-args.mm       (revision 0)
+++ testsuite/obj-c++.dg/too-many-args.mm       (revision 0)
@@ -0,0 +1,10 @@ 
+/* { dg-do compile } */
+
+@interface SomeClass
++ method:(int)foo;
+@end
+
+int main(void) {
+    [SomeClass method:3, 4];   /* { dg-error "too many arguments to method \\'method:\\'" } */
+    return 0;
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 164225)
+++ cp/typeck.c (working copy)
@@ -3428,8 +3428,17 @@ 
              "declared here");
     }
   else
-    error_at (loc, too_many_p ? G_("too many arguments to function")
-                             : G_("too few arguments to function"));
+    {
+      if (c_dialect_objc ()  &&  objc_message_selector ())
+       error_at (loc,
+                 too_many_p 
+                 ? G_("too many arguments to method %q#D")
+                 : G_("too few arguments to method %q#D"),
+                 objc_message_selector ());
+      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
Index: c-typeck.c
===================================================================
--- c-typeck.c  (revision 164225)
+++ c-typeck.c  (working copy)
@@ -2897,8 +2897,13 @@ 
 
       if (type == void_type_node)
        {
-         error_at (input_location,
-                   "too many arguments to function %qE", function);
+         if (selector)
+           error_at (input_location,
+                     "too many arguments to method %qE", selector);
+         else
+           error_at (input_location,
+                     "too many arguments to function %qE", function);
+
          if (fundecl && !DECL_BUILT_IN (fundecl))
            inform (DECL_SOURCE_LOCATION (fundecl), "declared here");
          return parmnum;