From patchwork Sun Sep 12 04:09:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 64540 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 81942B70A2 for ; Sun, 12 Sep 2010 14:09:42 +1000 (EST) Received: (qmail 21472 invoked by alias); 12 Sep 2010 04:09:35 -0000 Received: (qmail 21461 invoked by uid 22791); 12 Sep 2010 04:09:32 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 12 Sep 2010 04:09:26 +0000 Received: from eggs.gnu.org ([140.186.70.92]:58514) by fencepost.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oudsi-0002tA-QA for gcc-patches@gnu.org; Sun, 12 Sep 2010 00:09:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OudsY-0000O5-Tb for gcc-patches@gnu.org; Sun, 12 Sep 2010 00:09:24 -0400 Received: from smtp201.iad.emailsrvr.com ([207.97.245.201]:41439) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OudsY-0000Nz-Mm for gcc-patches@gnu.org; Sun, 12 Sep 2010 00:09:22 -0400 Received: from relay10.relay.iad.mlsrvr.com (localhost [127.0.0.1]) by relay10.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 61FDB1E966C for ; Sun, 12 Sep 2010 00:09:22 -0400 (EDT) Received: from dynamic3.wm-web.iad.mlsrvr.com (dynamic3.wm-web.iad.mlsrvr.com [192.168.2.152]) by relay10.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 5DB6B1E5F73 for ; Sun, 12 Sep 2010 00:09:22 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic3.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 4FD15332006E for ; Sun, 12 Sep 2010 00:09:22 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sun, 12 Sep 2010 06:09:22 +0200 (CEST) Date: Sun, 12 Sep 2010 06:09:22 +0200 (CEST) Subject: ObjC/ObjC++: fixed 'too many arguments to method xxx' error From: "Nicola Pero" To: gcc-patches@gnu.org MIME-Version: 1.0 X-Type: plain Message-ID: <1284264562.32429259@192.168.2.227> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.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;