From patchwork Fri Jan 7 00:21:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1576402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=hx/MRc9Z; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JVPN226Svz9sCD for ; Fri, 7 Jan 2022 11:33:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8A373858017 for ; Fri, 7 Jan 2022 00:33:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8A373858017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641515614; bh=tbfBldGqT3SWbvBa5NRVWaoyvKhuzprbvOiOJxBf9J8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=hx/MRc9Z1x+J57hTR4XGYIqgp31wh5XSZfQ0QHWPJwwkYIv0Q14a/+tfIrGMAHYmb 9uZqbsCLJPiwntJUICqjKPsojsgcd7NMJLjba/VJHuYtXBRxbU99LbZfkcg1behM4I qcRWEBAXJDZM8srmTIM+V1GOasgBg2j3edcGhuWQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5515E385803D for ; Fri, 7 Jan 2022 00:22:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5515E385803D Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-456-26Sp2SqvO3u47MyBbAJZWw-1; Thu, 06 Jan 2022 19:22:11 -0500 X-MC-Unique: 26Sp2SqvO3u47MyBbAJZWw-1 Received: by mail-qt1-f199.google.com with SMTP id h13-20020ac87d4d000000b002af9c496444so3315709qtb.22 for ; Thu, 06 Jan 2022 16:22:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tbfBldGqT3SWbvBa5NRVWaoyvKhuzprbvOiOJxBf9J8=; b=cetTw2XjKjRC/vKlu/TQtVBlL+JfTpusVT9jEZrSj5hJnc6b0LVZanGkLuqDNFR28B tYNzO2ZJKRyltC/CuWGOL57sbKbMQJyK4o9+jEaDcjk/yOJDHX/p1du12RqNf597koez 6pjSPguOkmR2jAj5Rb/a/psiaq/rI/iJ15SLBs46/8e4Kj3xHMl4FzMESU0Cx4McRbez VXnRVjuVpYnRiAxTF40vJC3BFVcAIG2DmMjm5FKVnGgSafvMEvDq+6OLh4fLN/O+Nvyn iuniFLzJwDBG0iHcDO8Nj08x+VxjtT+npFKmtziwvVH87IPnVlG8pigcZQEnYiYyhAPz 2qgg== X-Gm-Message-State: AOAM530mOBfLYtrx+/F+ZyXGu1uD2TVtiQl2gevcgykqJo8k1C3MmITf 1aA2h6Jl8oNi3n9kUCxW6ur4JxvbLm8+Oo8pvV4hPfwVqduHn1E2DbY3xiXpIyok2l6u7AzHytw ur6xI6Yw/PTRekQ69MytCdOi+U1H7sNLYaVY0a7wB7x8Fygp5+LeWpnDIHFhnOGhUkg== X-Received: by 2002:a05:6214:2386:: with SMTP id fw6mr6845176qvb.131.1641514931127; Thu, 06 Jan 2022 16:22:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSbRaNTRLAr05TwRQPfJa8D2wezsD910VgBerRO87ILNuz5FNzrCU8/R8sBXUJBXmTG2e2SA== X-Received: by 2002:a05:6214:2386:: with SMTP id fw6mr6845152qvb.131.1641514930757; Thu, 06 Jan 2022 16:22:10 -0800 (PST) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id s3sm2323785qkp.93.2022.01.06.16.22.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 16:22:09 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed 11/11] c++: when delegating constructor throws [PR103711] Date: Thu, 6 Jan 2022 19:21:56 -0500 Message-Id: <20220107002156.2992278-11-jason@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220107002156.2992278-1-jason@redhat.com> References: <20220107002156.2992278-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" We were always calling the complete destructor if the target constructor throws, even if we were calling the base constructor. PR c++/103711 gcc/cp/ChangeLog: * init.c (perform_target_ctor): Select destructor by in_chrg. gcc/testsuite/ChangeLog: * g++.dg/eh/delegating1.C: New test. --- gcc/cp/init.c | 10 ++++++++++ gcc/testsuite/g++.dg/eh/delegating1.C | 28 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/g++.dg/eh/delegating1.C diff --git a/gcc/cp/init.c b/gcc/cp/init.c index bfe4ad464bf..c932699ffa6 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -545,6 +545,16 @@ perform_target_ctor (tree init) |LOOKUP_NONVIRTUAL |LOOKUP_DESTRUCTOR, 0, tf_warning_or_error); + if (DECL_HAS_IN_CHARGE_PARM_P (current_function_decl)) + { + tree base = build_delete (input_location, + type, decl, sfk_base_destructor, + LOOKUP_NORMAL + |LOOKUP_NONVIRTUAL + |LOOKUP_DESTRUCTOR, + 0, tf_warning_or_error); + expr = build_if_in_charge (expr, base); + } if (expr != error_mark_node && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) finish_eh_cleanup (expr); diff --git a/gcc/testsuite/g++.dg/eh/delegating1.C b/gcc/testsuite/g++.dg/eh/delegating1.C new file mode 100644 index 00000000000..c33374a3b6b --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/delegating1.C @@ -0,0 +1,28 @@ +// PR c++/103711 +// { dg-do run { target c++11 } } + +int constructions = 0; +int destructions = 0; + +struct A +{ + A() { constructions++; } + virtual ~A() { destructions++; } +}; + +struct B : public virtual A +{ + B(int) { } + B() : B(1) { throw -1; } + virtual ~B() = default; +}; + +struct C : public B { }; + +int main() { + try { + C c; + } + catch (int) {} + return (constructions - destructions); +}