From patchwork Tue Nov 8 01:10:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 124232 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 EEF961007D5 for ; Tue, 8 Nov 2011 12:10:54 +1100 (EST) Received: (qmail 23292 invoked by alias); 8 Nov 2011 01:10:51 -0000 Received: (qmail 23284 invoked by uid 22791); 8 Nov 2011 01:10:50 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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, 08 Nov 2011 01:10:33 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pA81AWoa020119 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Nov 2011 20:10:32 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pA81AWKG026351 for ; Mon, 7 Nov 2011 20:10:32 -0500 Received: from [0.0.0.0] (ovpn-113-127.phx2.redhat.com [10.3.113.127]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pA81AV7o009427 for ; Mon, 7 Nov 2011 20:10:31 -0500 Message-ID: <4EB88186.7080006@redhat.com> Date: Mon, 07 Nov 2011 20:10:30 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50848 (ice-on-invalid with call to int&) 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 Here our code trying to give a helpful diagnostic for a call to an undeclared name in a template assumed that doing the lookup in instantiated context would find a function; in this testcase it finds an int&, and gets all confused. Tested x86_64-pc-linux-gnu, applying to trunk. commit 2bf99c2e68564b35f93f941a80fdc049e9a5d717 Author: Jason Merrill Date: Mon Nov 7 18:10:05 2011 -0500 PR c++/50848 * pt.c (tsubst_copy_and_build) [CALL_EXPR]: Don't crash if lookup finds a non-function. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 53a5358..bf2a2c6 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13673,6 +13673,8 @@ tsubst_copy_and_build (tree t, if (unq != function) { tree fn = unq; + if (TREE_CODE (fn) == INDIRECT_REF) + fn = TREE_OPERAND (fn, 0); if (TREE_CODE (fn) == COMPONENT_REF) fn = TREE_OPERAND (fn, 1); if (is_overloaded_fn (fn)) @@ -13682,7 +13684,9 @@ tsubst_copy_and_build (tree t, "and no declarations were found by " "argument-dependent lookup at the point " "of instantiation", function); - if (DECL_CLASS_SCOPE_P (fn)) + if (!DECL_P (fn)) + /* Can't say anything more. */; + else if (DECL_CLASS_SCOPE_P (fn)) { inform (EXPR_LOC_OR_HERE (t), "declarations in dependent base %qT are " diff --git a/gcc/testsuite/g++.dg/template/lookup9.C b/gcc/testsuite/g++.dg/template/lookup9.C new file mode 100644 index 0000000..4a1dc79 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/lookup9.C @@ -0,0 +1,10 @@ +// PR c++/50848 +// { dg-options "-fpermissive" } + +template class A {T& foo;}; +template class B: public A { + void f(){ + foo(1); // { dg-message "foo" } + } +}; +template class B;