From 467fc7c83abfe8fca8b75defac7c89f6c75bf9d7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 6 Apr 2020 18:19:07 -0400 Subject: [PATCH] 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 PR c++/94462 * decl.c (duplicate_decls): Fix handling of DECL_HIDDEN_FRIEND_P. --- 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(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-eq9.C 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 + + PR c++/94462 + * decl.c (duplicate_decls): Fix handling of DECL_HIDDEN_FRIEND_P. + 2020-04-04 Marek Polacek Jason Merrill 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); + }; +} + -- 2.30.2