[pushed] c++: defaulted friend op== [PR106361]

Message ID 20220721212144.467961-1-jason@redhat.com
State New, archived
Headers
Series [pushed] c++: defaulted friend op== [PR106361] |

Commit Message

Li, Pan2 via Gcc-patches July 21, 2022, 9:21 p.m. UTC
  Now non-member functions can be defaulted, so this assert is wrong.
move_signature_fn_p already checks for ctor or op=.

Tested x86_64-pc-linux-gnu, applying to trunk.

	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                              |  2 --
 gcc/testsuite/g++.dg/cpp2a/spaceship-eq14.C | 17 +++++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-eq14.C


base-commit: df118d7ba138cacb17203d4a1b5f27730347cc77
  

Patch

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index aa6cf3c6c2e..70ad681467e 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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
index 00000000000..896e5232bf6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq14.C
@@ -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" }
+}