From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 726DC3857B8B; Fri, 16 Feb 2024 20:52:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 726DC3857B8B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708116752; bh=eAz4lbaROGMu+tuqYV4lI3plRsrDkUycEXdFmKUhVp0=; h=From:To:Subject:Date:From; b=VFVSi65ukwgyeZwFgGMbbWFZ/8xWY8bKOIxr5KI45SIaLb3p39TNtKXaIv/b+bHXc FBVm/LLtk/0+RIXX3o4Yr+emLj5l+QSASvpv9sViBMr+R+8SuUHwkx64zcMPzISel+ byAzZqOVVSU1iK/JafDbCFOtTHRPN5hESLNko+3w= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9039] c++: wrong looser exception spec with deleted fn X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: c74131e77f1a6b7afe700d3526a8992dc9744b0c X-Git-Newrev: 40b8d7b73ad2ce498758c1d9bd38ebdbc26b918b Message-Id: <20240216205232.726DC3857B8B@sourceware.org> Date: Fri, 16 Feb 2024 20:52:32 +0000 (GMT) List-Id: https://gcc.gnu.org/g:40b8d7b73ad2ce498758c1d9bd38ebdbc26b918b commit r14-9039-g40b8d7b73ad2ce498758c1d9bd38ebdbc26b918b Author: Marek Polacek Date: Thu Feb 15 14:58:31 2024 -0500 c++: wrong looser exception spec with deleted fn 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. Diff: --- gcc/cp/search.cc | 11 +++++++++-- gcc/testsuite/g++.dg/cpp0x/noexcept82.C | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index 2b4ed5d024ea..c948839dc533 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 000000000000..c996613139b5 --- /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 +};