c++: Fix [[deprecated]] and implicit operator==. [PR97358]
authorJason Merrill <jason@redhat.com>
Thu, 15 Oct 2020 16:54:16 +0000 (12:54 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 15 Oct 2020 17:27:37 +0000 (13:27 -0400)
Trying to diagnose the problem with an implicit copy function breaks if the
function isn't actually a copy function.

gcc/cp/ChangeLog:

PR c++/95844
* decl.c (copy_fn_p): Return false for a function that is neither a
constructor nor an assignment operator.
(move_signature_fn_p): Likewise.

gcc/testsuite/ChangeLog:

PR c++/95844
* g++.dg/cpp2a/spaceship-eq10.C: New test.

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

index 2f1a2f0c554adfe8c41bce71bb982e88e6e026b3..5f370e60b4e809d7de45f23c697627cb239488f0 100644 (file)
@@ -14169,6 +14169,10 @@ copy_fn_p (const_tree d)
        accept those as copy functions.  */
     return 0;
 
+  if (!DECL_CONSTRUCTOR_P (d)
+      && DECL_NAME (d) != assign_op_identifier)
+    return 0;
+
   args = FUNCTION_FIRST_USER_PARMTYPE (d);
   if (!args)
     return 0;
@@ -14242,6 +14246,10 @@ move_signature_fn_p (const_tree d)
   tree arg_type;
   bool result = false;
 
+  if (!DECL_CONSTRUCTOR_P (d)
+      && DECL_NAME (d) != assign_op_identifier)
+    return 0;
+
   args = FUNCTION_FIRST_USER_PARMTYPE (d);
   if (!args)
     return 0;
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq10.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq10.C
new file mode 100644 (file)
index 0000000..93f5e25
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/95844
+// { dg-do compile { target c++20 } }
+
+#include <compare>
+
+struct F {
+  [[deprecated("oh no")]] std::strong_ordering operator<=>(const F&) const = default; // { dg-message "" }
+};
+void use_f(F f) {
+  void(f == f);                        // { dg-warning "deprecated" }
+}