[gcc/devel/ranger] c++: Fix ICE with implicit operator== [PR94462]
Aldy Hernandez
aldyh@gcc.gnu.org
Wed Jun 17 20:13:25 GMT 2020
https://gcc.gnu.org/g:467fc7c83abfe8fca8b75defac7c89f6c75bf9d7
commit 467fc7c83abfe8fca8b75defac7c89f6c75bf9d7
Author: Jason Merrill <jason@redhat.com>
Date: Mon Apr 6 18:19:07 2020 -0400
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.
Diff:
---
gcc/cp/ChangeLog | 5 +++++
gcc/cp/decl.c | 5 +++--
gcc/testsuite/g++.dg/cpp2a/spaceship-eq9.C | 17 +++++++++++++++++
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index fc75879d14f..02fd9cff79d 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 69a238997b4..a127734af69 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 00000000000..4f5df226410
--- /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);
+ };
+}
+
More information about the Gcc-cvs
mailing list