]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: defaulted friend op== [PR106361]
authorJason Merrill <jason@redhat.com>
Thu, 21 Jul 2022 00:00:58 +0000 (20:00 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 21 Jul 2022 21:22:57 +0000 (17:22 -0400)
Now non-member functions can be defaulted, so this assert is wrong.
move_signature_fn_p already checks for ctor or op=.

PR c++/106361

gcc/cp/ChangeLog:

* decl.cc (move_fn_p): Remove assert.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/spaceship-eq14.C: New test.

gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp2a/spaceship-eq14.C [new file with mode: 0644]

index f972bd50e75246ecf2171c3a8aa022c61d1dac74..9f78c500a15cf33e0478885f7a8f7fb92f68d426 100644 (file)
@@ -15016,8 +15016,6 @@ copy_fn_p (const_tree d)
 bool
 move_fn_p (const_tree d)
 {
-  gcc_assert (DECL_FUNCTION_MEMBER_P (d));
-
   if (cxx_dialect == cxx98)
     /* There are no move constructors if we are in C++98 mode.  */
     return false;
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq14.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq14.C
new file mode 100644 (file)
index 0000000..896e523
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/106361
+// { dg-do compile { target c++20 } }
+
+struct foo {
+  int x;
+};
+
+struct bar {
+  foo f;                       // { dg-error "operator==" }
+  friend bool operator==(const bar& a, const bar& b);
+};
+
+bool operator==(const bar& a, const bar& b) = default;
+
+int main() {
+  return bar{} == bar{};       // { dg-error "deleted" }
+}