aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-04-06 18:19:07 -0400
committerJason Merrill <jason@redhat.com>2020-04-07 00:11:44 -0400
commit467fc7c83abfe8fca8b75defac7c89f6c75bf9d7 (patch)
treedc9e116e3c0a14ab2658ef20cbbb2d7643a7c7ff
parent93a49d2d2292893b9b7f38132df949c70942838c (diff)
downloadgcc-467fc7c83abfe8fca8b75defac7c89f6c75bf9d7.zip
gcc-467fc7c83abfe8fca8b75defac7c89f6c75bf9d7.tar.gz
gcc-467fc7c83abfe8fca8b75defac7c89f6c75bf9d7.tar.bz2
c++: Fix ICE with implicit operator== [PR94462]
duplicate_decls assumed that any TREE_ARTIFICIAL function at namespace scope was a built-in function, but now in C++20 it's possible to have an implicitly declared hidden friend operator==. We just need to move the assert into the if condition. gcc/cp/ChangeLog 2020-04-06 Jason Merrill <jason@redhat.com> PR c++/94462 * decl.c (duplicate_decls): Fix handling of DECL_HIDDEN_FRIEND_P.
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/decl.c5
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/spaceship-eq9.C17
3 files changed, 25 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index fc75879..02fd9cf 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-06 Jason Merrill <jason@redhat.com>
+
+ PR c++/94462
+ * decl.c (duplicate_decls): Fix handling of DECL_HIDDEN_FRIEND_P.
+
2020-04-04 Marek Polacek <polacek@redhat.com>
Jason Merrill <jason@redhat.com>
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 69a2389..a127734 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -1451,9 +1451,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
/* Check for redeclaration and other discrepancies. */
if (TREE_CODE (olddecl) == FUNCTION_DECL
- && DECL_ARTIFICIAL (olddecl))
+ && DECL_ARTIFICIAL (olddecl)
+ /* A C++20 implicit friend operator== uses the normal path (94462). */
+ && !DECL_HIDDEN_FRIEND_P (olddecl))
{
- gcc_assert (!DECL_HIDDEN_FRIEND_P (olddecl));
if (TREE_CODE (newdecl) != FUNCTION_DECL)
{
/* Avoid warnings redeclaring built-ins which have not been
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq9.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq9.C
new file mode 100644
index 0000000..4f5df22
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq9.C
@@ -0,0 +1,17 @@
+// PR c++/94462
+// { dg-do compile { target c++2a } }
+
+namespace std {
+ struct strong_ordering { };
+}
+
+namespace Synth {
+ struct B {
+ friend std::strong_ordering operator<=>(B, B) = default;
+ };
+
+ struct C {
+ friend bool operator==(C, C);
+ };
+}
+