[pushed] c++: implicit operator== with previous decl [PR94583]
Marek Polacek
polacek@redhat.com
Sat Apr 25 22:54:49 GMT 2020
On Sat, Apr 25, 2020 at 12:17:18AM -0400, Jason Merrill via Gcc-patches wrote:
> P2085 clarified that a defaulted comparison operator must be the first
> declaration of the function. Rejecting that avoids the ICE trying to
> compare the noexcept-specifications.
>
> Tested x86_64-pc-linux-gnu, applying to trunk.
>
> gcc/cp/ChangeLog
> 2020-04-24 Jason Merrill <jason@redhat.com>
>
> PR c++/94583
> * decl.c (redeclaration_error_message): Reject defaulted comparison
> operator that has been previously declared.
> ---
> gcc/cp/decl.c | 8 ++++++++
> gcc/testsuite/g++.dg/cpp2a/spaceship-synth6.C | 11 +++++++++++
> 2 files changed, 19 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-synth6.C
>
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index c8c2f080763..31b5884ca3a 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -2972,6 +2972,14 @@ redeclaration_error_message (tree newdecl, tree olddecl)
> }
> }
>
> + /* [class.compare.default]: A definition of a comparison operator as
> + defaulted that appears in a class shall be the first declaration of
> + that function. */
> + special_function_kind sfk = special_function_p (olddecl);
> + if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
> + return G_("comparison operator %q+D defaulted after "
> + "its first declaration");
> +
This one still ICEs:
namespace std { struct strong_ordering { }; }
struct Q {
friend std::strong_ordering operator<=>(const Q&, const Q&) = default;
};
bool operator==(const Q&, const Q&) noexcept;
Either we need to reject redeclaring the implicit operator==, or teach
get_defaulted_eh_spec how to handle its DEFERRED_NOEXCEPT, before
build_comparison_op/~comp_info resolves it, because otherwise we couldn't
check that the noexcept-specifications match. Thoughts?
Marek
More information about the Gcc-patches
mailing list