public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: Fix [[deprecated]] and implicit operator==. [PR97358]
@ 2020-10-15 17:27 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2020-10-15 17:27 UTC (permalink / raw)
  To: gcc-patches

Trying to diagnose the problem with an implicit copy function breaks if the
function isn't actually a copy function.

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

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

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 2f1a2f0c554..5f370e60b4e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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
index 00000000000..93f5e253af4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq10.C
@@ -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" }
+}

base-commit: 08e712211efa4f969a64c69bdacf6ab45104a094
-- 
2.18.4


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-15 17:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 17:27 [pushed] c++: Fix [[deprecated]] and implicit operator==. [PR97358] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).