From patchwork Thu Feb 28 15:58:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 224112 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 632512C02C3 for ; Fri, 1 Mar 2013 02:59:07 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1362671947; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=15y8t3pxoU3kmPtL9zuULevNU6g=; b=yUg698mubqCWEd8 ghxC+eJoae4QDuB4tVGjC7btpYG82+wOKQqmad62eHiQMeDq4QJk+0GFfytXA/aX mFryUBdf22afFS3efNrB+303+CsUBy+OkgIdUkhCFotIRCcH/19aZ4uSK56DeGgp XubpuIozvAgfc/LN4CKUoYy7G8Nk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=JxfgJms2/9+me71SczSyqiTP82GpSk0QQc+ll2H8J1o/5Kanunl0MZZf716GBW 0MTYaCrK/wbFnR4FJ8zozr6kthVewarxTK/oCiAwArmRcls0oAafnv57GTpZaz0H eCZmxfgr7nUwRIcRHlFnnJ4pTqamLMgVKUIO1RxK/m6jY=; Received: (qmail 12026 invoked by alias); 28 Feb 2013 15:58:55 -0000 Received: (qmail 12007 invoked by uid 22791); 28 Feb 2013 15:58:55 -0000 X-SWARE-Spam-Status: No, hits=-7.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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; Thu, 28 Feb 2013 15:58:51 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1SFwoxn000328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 28 Feb 2013 10:58:51 -0500 Received: from [10.3.113.60] (ovpn-113-60.phx2.redhat.com [10.3.113.60]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1SFwoON032202; Thu, 28 Feb 2013 10:58:50 -0500 Message-ID: <512F7EBA.4010704@redhat.com> Date: Thu, 28 Feb 2013 10:58:50 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: =?ISO-8859-1?Q?Fabien_Ch=EAne?= , GCC Patches Subject: Re: [C++ Patch] Fix c++/56243 References: <512BF2B3.1070106@redhat.com> <512BF2F9.6060901@redhat.com> In-Reply-To: <512BF2F9.6060901@redhat.com> 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 On 02/25/2013 06:25 PM, Jason Merrill wrote: > On 02/25/2013 06:24 PM, Jason Merrill wrote: >> I think my preference would be to avoid calling fixed_type_or_null at >> all when we're in a template. I already changed >> resolves_to_fixed_type_p that way, now we need to fix build_vtbl_ref_1. > > Oops, now I see the discussion on the PR. I'll take a look. I'm applying this patch. When we're in fold_non_dependent_expr we care about doing the right thing for possible constant-expressions, but a virtual function call can't be part of a constant-expression, so we don't need to worry about virtual lookup. Tested x86_64-pc-linux-gnu, applying to trunk. commit 8d561a71fbe141ad4d5b4f1ff9160e4f4c81a061 Author: Jason Merrill Date: Tue Feb 26 10:06:31 2013 -0500 PR c++/56243 * call.c (build_over_call): Avoid virtual lookup in a template. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 7c41421..4eb38ec 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7033,7 +7033,10 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) if (!already_used) mark_used (fn); - if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0) + if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0 + /* Don't mess with virtual lookup in fold_non_dependent_expr; virtual + functions can't be constexpr. */ + && !in_template_function ()) { tree t; tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (argarray[0])), diff --git a/gcc/testsuite/g++.dg/template/virtual4.C b/gcc/testsuite/g++.dg/template/virtual4.C new file mode 100644 index 0000000..a2c7420b --- /dev/null +++ b/gcc/testsuite/g++.dg/template/virtual4.C @@ -0,0 +1,30 @@ +// PR c++/56243 + +struct A +{ + virtual int String (); +}; + +struct F: A { }; + +struct G +{ + F value; +}; + +struct D +{ + template + void Verify() + { + G x; + F& name = x.value; + name.String(); + } +}; + +int main() +{ + D d; + d.Verify<42>(); +}