From patchwork Sat Aug 1 23:31:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 502876 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3B5F614030E for ; Sun, 2 Aug 2015 09:31:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=kSrYf0DY; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=waOmf+TtxnnxU+Fbw 6VYf/OHwFg0ysIu2jpALIbPsHO9ojDuDCSCK1hNSfT3gFUH8hccISme8cmedLBy2 TSeq2bTjRoxKDdPls2WvZh+O08PApE4us9QnznZ7A/mJErlK8cHHuGS1uEiKvMG1 QLSabWlk8v++zK1TS1cunJo1Ck= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=1gNpYQci0f7AqJODRk3HigU 4VsA=; b=kSrYf0DY32/DeA+0vf8y2rk7HaPBU2QDX7deY7bvdGXnQmp45FprWuB szgWUVNL0JCeGYIYhPRuPc1kX+ZJazseZ4C5Eb17upObMyMbVQAgHAQXKES5NwQR XCaUnfDjjFBubC3Gr+1jLScx3OJLVo0r6nr8ghRMdq5CEnF8t1g4= Received: (qmail 29838 invoked by alias); 1 Aug 2015 23:31:34 -0000 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 Received: (qmail 29829 invoked by uid 89); 1 Aug 2015 23:31:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qg0-f49.google.com Received: from mail-qg0-f49.google.com (HELO mail-qg0-f49.google.com) (209.85.192.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 01 Aug 2015 23:31:32 +0000 Received: by qgeu79 with SMTP id u79so68496122qge.1 for ; Sat, 01 Aug 2015 16:31:30 -0700 (PDT) X-Received: by 10.140.108.130 with SMTP id j2mr15842402qgf.83.1438471890183; Sat, 01 Aug 2015 16:31:30 -0700 (PDT) Received: from ?IPv6:2601:181:c000:c497:a2a8:cdff:fe3e:b48? ([2601:181:c000:c497:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id 65sm4474848qks.30.2015.08.01.16.31.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Aug 2015 16:31:29 -0700 (PDT) Subject: Re: [C++/66443] virtual base of abstract class To: Jason Merrill , GCC Patches References: <5591CD50.1040102@acm.org> <559218D8.6080701@redhat.com> <5593247E.5000508@acm.org> <559D38B9.1080404@acm.org> <55A95AB9.6050105@redhat.com> <55A95E99.7020309@acm.org> From: Nathan Sidwell Message-ID: <55BD56D0.601@acm.org> Date: Sat, 1 Aug 2015 19:31:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <55A95E99.7020309@acm.org> On 07/17/15 15:59, Nathan Sidwell wrote: > On 07/17/15 15:42, Jason Merrill wrote: >> On 07/08/2015 10:50 AM, Nathan Sidwell wrote: >>> On 06/30/15 19:21, Nathan Sidwell wrote: >>>> On 06/30/15 00:19, Jason Merrill wrote: >>>>> On 06/29/2015 06:57 PM, Nathan Sidwell wrote: >>>>>> * method.c (synthesized_method_walk): Skip virtual bases of >>>>>> abstract classes in C++14 mode. >>>>> >>>>> Let's not limit this to C++14 mode; most DRs apply to earlier >>>>> standards as well. >>> >>> curiously opening it up leads to some test failures related to >>> determining the exception specifier for implicit ctors and dtors. Not >>> had time to investigate that yet ... >> >> If C++98 mode is problematic, we can limit this to C++11 and up. > > I'm not yet sure. The failure mode I saw surprised me, and suggests there's > something wrong with the patch. Sadly, I've got interrupted by other stuff. Ok, this patch fixes things up. The previous version was a little too lax, extending the logic of DR1611 to all synthesized functions. However, this broke virtual synthesized dtors, in that an abstract class's synthesized dtor's exception specification would not take account of any virtual base dtor exception specs. This would mean that a non-abstract derived class's synthesized dtor might end up with a throwing exception spec (because the virtual base's dtor did), and that would be looser than the exception spec on the abstract base's non-callable synthesized dtor. And that fails the virtual overriding checks. So this restricts the skipping to exactly what DR 1611 discusses -- default constructors of virtual bases of an abstract class. Those can never be virtual, so we don't end up with the above problem in that case. Jason, WDYT? nathan 2015-08-01 Nathan Sidwell cp/ PR c++/66443 * init.c (emit_mem_initializers): Do not emit initializers for virtual bases of abstract classes. * method.c (synthesized_method_walk): Skip virtual bases of abstract classes in C++14 mode. testsuite/ PR c++/66443 * cpp1y/pr66443.C: New test. Index: cp/init.c =================================================================== --- cp/init.c (revision 226444) +++ cp/init.c (working copy) @@ -1140,9 +1140,7 @@ emit_mem_initializers (tree mem_inits) } /* Initialize the base. */ - if (BINFO_VIRTUAL_P (subobject)) - construct_virtual_base (subobject, arguments); - else + if (!BINFO_VIRTUAL_P (subobject)) { tree base_addr; @@ -1156,6 +1154,8 @@ emit_mem_initializers (tree mem_inits) tf_warning_or_error); expand_cleanup_for_base (subobject, NULL_TREE); } + else if (!ABSTRACT_CLASS_TYPE_P (current_class_type)) + construct_virtual_base (subobject, arguments); } in_base_initializer = 0; Index: cp/method.c =================================================================== --- cp/method.c (revision 226444) +++ cp/method.c (working copy) @@ -1506,7 +1506,13 @@ synthesized_method_walk (tree ctype, spe vbases = CLASSTYPE_VBASECLASSES (ctype); if (vec_safe_is_empty (vbases)) /* No virtual bases to worry about. */; - else if (!assign_p) + else if (!assign_p + /* DR 1611 ignores virtual bases of abstract classes for + the default constructor. Such ctors can never be + directly called. Thus their deletion should not affect + whether they are deleted in this class. */ + && (!ABSTRACT_CLASS_TYPE_P (ctype) || sfk != sfk_constructor + || inherited_parms)) { if (constexpr_p) *constexpr_p = false; Index: testsuite/g++.dg/other/pr66443.C =================================================================== --- testsuite/g++.dg/other/pr66443.C (revision 0) +++ testsuite/g++.dg/other/pr66443.C (working copy) @@ -0,0 +1,21 @@ +// { dg-do compile } + +class A { +public: + A( int ) { } +}; + +// B's virtual base is ignored for default ctor determination as B is +// abstract. DR1611 & DR1658 + +class B: virtual public A { +public: + virtual void do_something() = 0; +}; + +class C: public B { +public: + C(): A( 1 ) { } + virtual void do_something() { } +}; +