From patchwork Sun Sep 12 04:09:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: ObjC/ObjC++: fixed 'too many arguments to method xxx' error Date: Sat, 11 Sep 2010 18:09:22 -0000 From: Nicola Pero X-Patchwork-Id: 64540 Message-Id: <1284264562.32429259@192.168.2.227> To: gcc-patches@gnu.org 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 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;