From patchwork Thu Mar 29 02:53:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 149356 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 10BEEB6EEC for ; Thu, 29 Mar 2012 13:53:48 +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=1333594429; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=xXyUqT+ s1GSOApXggX+0Dn9xwJQ=; b=DQd2Etm43s1w2p5D/vInSZ42B/k4yTEwhnIjyK6 m4SY69XvNaHSx6JI1ucN4uLFixsSu1voW7YZKaYIySxwuNsDGhT4tcicZX9g6CVY OKQXNfTo+58RlrrHM7LRtA6oH6FPBnxPJ3wERzqDvaS1uT7pzxb7oYr7lIUO1dFP rUv0= 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:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=K1EHLrLtcyoAiTngLoa5lsz7/q9IKmIkdqZGiWQ/b/lHj0xLglPWQkPeTEpzql pjOHdd7hVUNtDP2FPUr+nYExAPH/zQ25CpS7eMBMWDXxHEuOhRTqHmXjUvpJKCkN ZqiKOW5/WrDdoURkHFEJRJGJVuTZVvUdtuDSdiQ+XG5+g=; Received: (qmail 18578 invoked by alias); 29 Mar 2012 02:53:43 -0000 Received: (qmail 18567 invoked by uid 22791); 29 Mar 2012 02:53:41 -0000 X-SWARE-Spam-Status: No, hits=-6.6 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; Thu, 29 Mar 2012 02:53:25 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2T2rPFP022865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 28 Mar 2012 22:53:25 -0400 Received: from [10.3.113.47] (ovpn-113-47.phx2.redhat.com [10.3.113.47]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q2T2rORB028728 for ; Wed, 28 Mar 2012 22:53:25 -0400 Message-ID: <4F73CEA4.3080001@redhat.com> Date: Wed, 28 Mar 2012 22:53:24 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/52746 (virtual destructors broken in templates) 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 In my fix for PR 48051 I failed to audit all the users of adjust_result_of_qualified_name_lookup to make sure it wasn't being called for non-qualified lookups as well; in this case we were calling it for an explicit destructor call, and now that we set BASELINK_QUALIFIED_P in that function, we were suppressing virtual calling semantics inappropriately. Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit 1f230c968d34b5c48ad50f83e8774de52d04d653 Author: Jason Merrill Date: Wed Mar 28 20:59:26 2012 -0400 PR c++/52746 * typeck.c (lookup_destructor): Clear BASELINK_QUALIFIED_P if we didn't get an explicit scope. * pt.c (tsubst_baselink): Likewise. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f128947..9b410a7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11814,6 +11814,7 @@ tsubst_baselink (tree baselink, tree object_type, tree optype; tree template_args = 0; bool template_id_p = false; + bool qualified = BASELINK_QUALIFIED_P (baselink); /* A baselink indicates a function from a base class. Both the BASELINK_ACCESS_BINFO and the base class referenced may @@ -11862,9 +11863,12 @@ tsubst_baselink (tree baselink, tree object_type, if (!object_type) object_type = current_class_type; - return adjust_result_of_qualified_name_lookup (baselink, - qualifying_scope, - object_type); + + if (qualified) + baselink = adjust_result_of_qualified_name_lookup (baselink, + qualifying_scope, + object_type); + return baselink; } /* Like tsubst_expr for a SCOPE_REF, given by QUALIFIED_ID. DONE is diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index b68de52..d2ed940 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2415,6 +2415,11 @@ lookup_destructor (tree object, tree scope, tree dtor_name) tf_warning_or_error); expr = (adjust_result_of_qualified_name_lookup (expr, dtor_type, object_type)); + if (scope == NULL_TREE) + /* We need to call adjust_result_of_qualified_name_lookup in case the + destructor names a base class, but we unset BASELINK_QUALIFIED_P so + that we still get virtual function binding. */ + BASELINK_QUALIFIED_P (expr) = false; return expr; } diff --git a/gcc/testsuite/g++.dg/overload/virtual2.C b/gcc/testsuite/g++.dg/overload/virtual2.C new file mode 100644 index 0000000..c93ba9e --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/virtual2.C @@ -0,0 +1,31 @@ +// PR c++/52746 +// { dg-do run } + +extern "C" int printf(const char*,...); +extern "C" void abort(); +bool db; + +struct A +{ + virtual ~A() {} +}; + +struct B : public A +{ + virtual ~B() { db = true; } +}; + +template void test() +{ + B * b = new B; + A * a = b; + a->~A(); + ::operator delete(b); +} + +int main() +{ + test<0>(); + if (!db) + abort(); +}