From b804bd89d3a8ff3ab6b916d2982b83f805cc6256 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 21 Dec 2019 00:19:23 +0100 Subject: [PATCH] re PR c++/92966 (Segfault on defaulted operator== with wrong return type) PR c++/92966 * method.c (early_check_defaulted_comparison): Don't set DECL_MAYBE_DELETED when returning false. * g++.dg/cpp2a/spaceship-eq8.C: New test. From-SVN: r279683 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/method.c | 2 +- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp2a/spaceship-eq8.C | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-eq8.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 07200ad21e5..4ccee73cc39 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-12-20 Jakub Jelinek + PR c++/92966 + * method.c (early_check_defaulted_comparison): Don't set + DECL_MAYBE_DELETED when returning false. + PR c++/92973 * method.c (early_check_defaulted_comparison): For C++17 and earlier diagnose defaulted comparison operators. diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 248a0e55f06..69e1262ece0 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1153,7 +1153,7 @@ early_check_defaulted_comparison (tree fn) } /* We still need to deduce deleted/constexpr/noexcept and maybe return. */ - DECL_MAYBE_DELETED (fn) = true; + DECL_MAYBE_DELETED (fn) = ok; return ok; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 40568bb98be..b357e1e8fcb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-12-20 Jakub Jelinek + PR c++/92966 + * g++.dg/cpp2a/spaceship-eq8.C: New test. + PR c++/92973 * g++.dg/cpp0x/spaceship-eq1.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq8.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq8.C new file mode 100644 index 00000000000..aabbd324d86 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq8.C @@ -0,0 +1,8 @@ +// PR c++/92966 +// { dg-do compile { target c++2a } } + +struct S { + int operator==(const S&) const = default; // { dg-error "must return 'bool'" } + int s; // { dg-message "declared here" "" { target *-*-* } .-1 } +}; +static_assert(S{} == S{}); // { dg-error "" } -- 2.30.2