From patchwork Mon Feb 28 21:40:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 84868 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 24EB6B714A for ; Tue, 1 Mar 2011 08:40:57 +1100 (EST) Received: (qmail 20663 invoked by alias); 28 Feb 2011 21:40:55 -0000 Received: (qmail 20651 invoked by uid 22791); 28 Feb 2011 21:40:55 -0000 X-SWARE-Spam-Status: No, hits=-6.2 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; Mon, 28 Feb 2011 21:40:46 +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 p1SLej8F025013 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 28 Feb 2011 16:40:45 -0500 Received: from [127.0.0.1] (ovpn-113-31.phx2.redhat.com [10.3.113.31]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1SLeiaN028566 for ; Mon, 28 Feb 2011 16:40:44 -0500 Message-ID: <4D6C165B.3070508@redhat.com> Date: Mon, 28 Feb 2011 16:40:43 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/47873 (bad code with covariant virtuals) 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 When I rewrote our covariant thunk handling to fix 43120, I was confused about what BINFO_LOST_PRIMARY_P meant; I thought it meant that the binfo was itself a lost primary, rather than that the binfo lost its primary. So I put the tests in the wrong order: a binfo with BINFO_LOST_PRIMARY_P is still interesting, it's its primary that we aren't interested in. So we need to check for a non-thunk before we check BINFO_LOST_PRIMARY_P. Tested x86_64-pc-linux-gnu, applied to trunk. commit 421e8d4642b0639dc3fca4478d661a76ee5aa022 Author: Jason Merrill Date: Mon Feb 28 13:13:03 2011 -0500 PR c++/47873 * class.c (update_vtable_entry_for_fn): Check BINFO_LOST_PRIMARY_P after checking for a non-thunk. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 0d485fc..1325260 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2250,10 +2250,10 @@ update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals, { tree main_binfo = TYPE_BINFO (BINFO_TYPE (b)); tree bv = chain_index (ix, BINFO_VIRTUALS (main_binfo)); + if (!DECL_THUNK_P (TREE_VALUE (bv))) + break; if (BINFO_LOST_PRIMARY_P (b)) lost = true; - if (!DECL_THUNK_P (TREE_VALUE (bv))) - break; } first_defn = b; } diff --git a/gcc/testsuite/g++.dg/inherit/covariant18.C b/gcc/testsuite/g++.dg/inherit/covariant18.C new file mode 100644 index 0000000..31e6216 --- /dev/null +++ b/gcc/testsuite/g++.dg/inherit/covariant18.C @@ -0,0 +1,41 @@ +// PR c++/47873 +// { dg-do run } + +struct Base +{ + virtual ~Base(){} + + virtual Base& This() { return *this; } +}; + + +struct Ent : virtual Base +{ + void *m_Body; + + Ent& This() { return *this; } + + virtual Ent& body() + { + return This(); + } + +}; + + +struct Msg : virtual Ent +{ + Msg() + { + body(); + } + + Msg& This() { return *this; } +}; + +int main() +{ + Msg m; + + return 0; +}