public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/gccgo] c++: implicit operator== with previous decl [PR94583]
@ 2020-07-12 17:33 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2020-07-12 17:33 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:352811870d7d7edcca109ef50822e26ca7ef2b36

commit 352811870d7d7edcca109ef50822e26ca7ef2b36
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Apr 24 16:27:26 2020 -0400

    c++: implicit operator== with previous decl [PR94583]
    
    P2085 clarified that a defaulted comparison operator must be the first
    declaration of the function.  Rejecting that avoids the ICE trying to
    compare the noexcept-specifications.
    
    gcc/cp/ChangeLog
    2020-04-24  Jason Merrill  <jason@redhat.com>
    
            PR c++/94583
            * decl.c (redeclaration_error_message): Reject defaulted comparison
            operator that has been previously declared.

Diff:
---
 gcc/cp/ChangeLog                              |  6 ++++++
 gcc/cp/decl.c                                 |  8 ++++++++
 gcc/testsuite/g++.dg/cpp2a/spaceship-synth6.C | 11 +++++++++++
 3 files changed, 25 insertions(+)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2a5b4171366..f0c62783101 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-24  Jason Merrill  <jason@redhat.com>
+
+	PR c++/94583
+	* decl.c (redeclaration_error_message): Reject defaulted comparison
+	operator that has been previously declared.
+
 2020-04-25  Patrick Palka  <ppalka@redhat.com>
 
 	* parser.c (cp_parser_diagnose_invalid_type_name): Suggest enabling
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c8c2f080763..31b5884ca3a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2972,6 +2972,14 @@ redeclaration_error_message (tree newdecl, tree olddecl)
 	    }
 	}
 
+      /* [class.compare.default]: A definition of a comparison operator as
+	 defaulted that appears in a class shall be the first declaration of
+	 that function.  */
+      special_function_kind sfk = special_function_p (olddecl);
+      if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
+	return G_("comparison operator %q+D defaulted after "
+		  "its first declaration");
+
       check_abi_tag_redeclaration
 	(olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
 	 lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth6.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth6.C
new file mode 100644
index 00000000000..e8296bbb60a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth6.C
@@ -0,0 +1,11 @@
+// PR c++/94583
+// { dg-do compile { target c++2a } }
+
+namespace std { struct strong_ordering { }; }
+
+bool operator==(const struct Q&, const struct Q&);
+struct Q {
+  // { dg-error "defaulted after its first declaration" "" { target *-*-* } .+1 }
+  friend std::strong_ordering operator<=>(const Q&, const Q&) = default;
+};
+bool b = Q() == Q();


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

only message in thread, other threads:[~2020-07-12 17:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-12 17:33 [gcc/devel/gccgo] c++: implicit operator== with previous decl [PR94583] Ian Lance Taylor

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).