* [PATCH] c++: wrong looser exception spec with deleted fn
@ 2024-02-15 22:16 Marek Polacek
2024-02-16 20:48 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2024-02-15 22:16 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
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
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
+};
base-commit: 0d5d1c75f5c68b6064640c3154ae5f4c0b464905
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: wrong looser exception spec with deleted fn
2024-02-15 22:16 [PATCH] c++: wrong looser exception spec with deleted fn Marek Polacek
@ 2024-02-16 20:48 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-02-16 20:48 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 2/15/24 17:16, Marek Polacek wrote:
> 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.
OK.
> -- >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
>
> 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
> +};
>
> base-commit: 0d5d1c75f5c68b6064640c3154ae5f4c0b464905
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-16 20:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-15 22:16 [PATCH] c++: wrong looser exception spec with deleted fn Marek Polacek
2024-02-16 20:48 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).