From patchwork Sat Nov 6 01:43:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 70318 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 09EFFB7113 for ; Sat, 6 Nov 2010 12:43:33 +1100 (EST) Received: (qmail 27249 invoked by alias); 6 Nov 2010 01:43:31 -0000 Received: (qmail 27233 invoked by uid 22791); 6 Nov 2010 01:43:31 -0000 X-SWARE-Spam-Status: No, hits=-6.1 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; Sat, 06 Nov 2010 01:43:26 +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.13.8/8.13.8) with ESMTP id oA61hPFh022304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 5 Nov 2010 21:43:25 -0400 Received: from [127.0.0.1] ([10.3.113.16]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oA61hOIv016227 for ; Fri, 5 Nov 2010 21:43:24 -0400 Message-ID: <4CD4B2BC.2090709@redhat.com> Date: Fri, 05 Nov 2010 21:43:24 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101104 Lightning/1.0b1 Shredder/3.0.11pre MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/45473 (ICE with base virtual function named the same as derived class) 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 this testcase, we've always (at least as far back as 2.95) treated B::B() as overriding A::B(), which is wrong; constructors do not have names, so they cannot have the same name as a virtual function. I was worried that this was going to be an ABI issue, but fortunately the testcase never actually compiled; past GCC versions emitted ill-formed assembly. Tested x86_64-pc-linux-gnu, applied to trunk. commit 650267e2d691dd2c42049a0214a6f691e72cb8e3 Author: Jason Merrill Date: Fri Nov 5 20:40:28 2010 -0400 PR c++/45473 * search.c (look_for_overrides): A constructor is never virtual. diff --git a/gcc/cp/search.c b/gcc/cp/search.c index 0249fb0..76bf47c 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -1935,6 +1935,9 @@ look_for_overrides (tree type, tree fndecl) int ix; int found = 0; + if (DECL_CONSTRUCTOR_P (fndecl)) + return 0; + for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++) { tree basetype = BINFO_TYPE (base_binfo); diff --git a/gcc/testsuite/g++.dg/inherit/virtual6.C b/gcc/testsuite/g++.dg/inherit/virtual6.C new file mode 100644 index 0000000..f036969 --- /dev/null +++ b/gcc/testsuite/g++.dg/inherit/virtual6.C @@ -0,0 +1,15 @@ +// PR c++/45473 + +struct A +{ + virtual void B (); +}; + +struct B : A +{ + B (); +}; + +struct C : B +{ +};