]> gcc.gnu.org Git - 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:21:22 +0000 (17:21 -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 aa6cf3c6c2eb827d12f5badf7edfbae4884a11a3..70ad681467ee36b9b6e54e85afb9d0988e3e8eba 100644 (file)
@@ -15022,8 +15022,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" }
+}
This page took 0.09814 seconds and 5 git commands to generate.