re PR c++/92966 (Segfault on defaulted operator== with wrong return type)
authorJakub Jelinek <jakub@redhat.com>
Fri, 20 Dec 2019 23:19:23 +0000 (00:19 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 20 Dec 2019 23:19:23 +0000 (00:19 +0100)
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
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/spaceship-eq8.C [new file with mode: 0644]

index 07200ad21e5b5c2539b33f40e4ed73cf3b37d389..4ccee73cc39aa957a15897fdd08fc505ce9d8910 100644 (file)
@@ -1,5 +1,9 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
+       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.
index 248a0e55f06e3cf4a66081c3195b8e5609a901d6..69e1262ece008f51876fbf874e52a1a4c13af5df 100644 (file)
@@ -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;
 }
index 40568bb98be8c036a6e07dfff5ec11e029f80fd0..b357e1e8fcbe4799f9ee244530809f43809eb630 100644 (file)
@@ -1,5 +1,8 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
+       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 (file)
index 0000000..aabbd32
--- /dev/null
@@ -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 "" }