From patchwork Thu Feb 15 22:16:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1899833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=E/TncIsm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TbTvY1KS1z23jJ for ; Fri, 16 Feb 2024 09:17:29 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0D596386EC1D for ; Thu, 15 Feb 2024 22:17:27 +0000 (GMT) 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 4E35F386D604 for ; Thu, 15 Feb 2024 22:17:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E35F386D604 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4E35F386D604 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708035425; cv=none; b=to/JiJPkvR2lq/PnDzIdn2atHmuwQJZWVIPci7ToNIzLno1E5QeXl6FoDg60gTgV5cG6oAcPjg3SXeNnWXHKSsXPVQnDhbGj/zDpv0krrCReEXjgyNXviUoRVIEdZFVD1sqUICltDSqsopv497nETXprAkhYqNAXNCWBymN2o0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708035425; c=relaxed/simple; bh=nNgYoC4sKDcjGT/0urZYedwQqJJWOiHtE3MZ/toSJ/0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KDhRESeOOjpbsX4aw2khI5rUZbkNwCZxeC5o8g6ZAj/0Vff4UooSxuyY9P/CTYXh32hA+FkkXopMA6iwCucVMb4rgLvpkTT/hETAQKakdBMhngawAALVn+5NmzBxDjT6wQ/t8g3lxBIMrDeUalYtVb0eqiXf/dO2Yxmx3PZcVUI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708035423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oAnlB6mWxJlOA3iGp81hQhGnuNPUORwuM43rgc3WKTE=; b=E/TncIsmFKnjwGOPhShht4U5urth+agO2muX4eLYRhak+Yo4zpR/YSWVRxWOf92lT57i10 ONX5EZNSFLhX4z149JPfEOu1qphBITbBNogh+WOUva7/wSWl7by/ZtWtL+GdPZDpHtnhD1 +GH7NdMudWhD1zt8rjMQaNDHkrpIpEo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-580-q7if1DlEN2yM57ivt1014w-1; Thu, 15 Feb 2024 17:16:59 -0500 X-MC-Unique: q7if1DlEN2yM57ivt1014w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A8AD83722D for ; Thu, 15 Feb 2024 22:16:59 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.33.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD941492BC6; Thu, 15 Feb 2024 22:16:58 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: wrong looser exception spec with deleted fn Date: Thu, 15 Feb 2024 17:16:54 -0500 Message-ID: <20240215221654.646716-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? IMHO trivial enough to go ahead now seeing as it doesn't introduce new errors. -- >8 -- I noticed we don't implement the "unless the overriding function is defined as deleted" wording added to [except.spec] via CWG 1351. DR 1351 gcc/cp/ChangeLog: * search.cc (maybe_check_overriding_exception_spec): Don't error about a looser exception specification if the overrider is deleted. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept82.C: New test. --- gcc/cp/search.cc | 11 +++++++++-- gcc/testsuite/g++.dg/cpp0x/noexcept82.C | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept82.C base-commit: 0d5d1c75f5c68b6064640c3154ae5f4c0b464905 diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index 2b4ed5d024e..c948839dc53 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -1949,7 +1949,11 @@ locate_field_accessor (tree basetype_path, tree field_decl, bool const_p) } /* Check throw specifier of OVERRIDER is at least as strict as - the one of BASEFN. */ + the one of BASEFN. This is due to [except.spec]: "If a virtual function + has a non-throwing exception specification, all declarations, including + the definition, of any function that overrides that virtual function in + any derived class shall have a non-throwing exception specification, + unless the overriding function is defined as deleted." */ bool maybe_check_overriding_exception_spec (tree overrider, tree basefn) @@ -1959,7 +1963,10 @@ maybe_check_overriding_exception_spec (tree overrider, tree basefn) tree base_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (basefn)); tree over_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (overrider)); - if (DECL_INVALID_OVERRIDER_P (overrider)) + if (DECL_INVALID_OVERRIDER_P (overrider) + /* CWG 1351 added the "unless the overriding function is defined as + deleted" wording. */ + || DECL_DELETED_FN (overrider)) return true; /* Can't check this yet. Pretend this is fine and let diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept82.C b/gcc/testsuite/g++.dg/cpp0x/noexcept82.C new file mode 100644 index 00000000000..c996613139b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept82.C @@ -0,0 +1,14 @@ +// DR 1351, Problems with implicitly-declared exception-specifications +// { dg-do compile { target c++11 } } + +struct B { + virtual void f() noexcept; + virtual void g(); + virtual void h() noexcept = delete; +}; + +struct D: B { + void f(); // { dg-error "looser" } + void g() noexcept; // OK + void h() = delete; // OK +};