From patchwork Tue Jun 22 13:50:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 56499 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 B266CB6EDD for ; Tue, 22 Jun 2010 23:49:57 +1000 (EST) Received: (qmail 2077 invoked by alias); 22 Jun 2010 13:49:46 -0000 Received: (qmail 2060 invoked by uid 22791); 22 Jun 2010 13:49:44 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Jun 2010 13:49:37 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5MDnaMm013156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 22 Jun 2010 09:49:36 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5MDnY3O020632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 22 Jun 2010 09:49:35 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o5MDo748016708; Tue, 22 Jun 2010 15:50:07 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o5MDo7Ck016706; Tue, 22 Jun 2010 15:50:07 +0200 Date: Tue, 22 Jun 2010 15:50:07 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix C++ diagnostic ICE on invalid method call Message-ID: <20100622135007.GR7811@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) 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 Hi! On valid code obviously calls to methods need to have at least one arguments, but on invalid code like this they sometimes don't. The diagnostic printer should be IMHO extra careful. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-06-22 Jakub Jelinek PR c++/44627 * error.c (dump_expr): Don't look at CALL_EXPR_ARG (t, 0) if the CALL_EXPR has no arguments. * g++.dg/diagnostic/method1.C: New test. Jakub --- gcc/cp/error.c.jj 2010-06-20 16:36:49.000000000 +0200 +++ gcc/cp/error.c 2010-06-22 11:45:04.000000000 +0200 @@ -1759,7 +1759,9 @@ dump_expr (tree t, int flags) if (TREE_CODE (fn) == OBJ_TYPE_REF) fn = resolve_virtual_fun_from_obj_type_ref (fn); - if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE) + if (TREE_TYPE (fn) != NULL_TREE + && NEXT_CODE (fn) == METHOD_TYPE + && call_expr_nargs (t)) { tree ob = CALL_EXPR_ARG (t, 0); if (TREE_CODE (ob) == ADDR_EXPR) --- gcc/testsuite/g++.dg/diagnostic/method1.C.jj 2010-06-22 11:51:31.000000000 +0200 +++ gcc/testsuite/g++.dg/diagnostic/method1.C 2010-06-22 11:56:40.000000000 +0200 @@ -0,0 +1,20 @@ +// PR c++/44627 +// { dg-do compile } + +struct A +{ + A *foo (); +}; + +template +void +bar () +{ + A::foo ().anything; // { dg-error "request for member" } +} + +void +baz () +{ + bar (); +}