Bootstrapped and regtested on x86_64-pc-linux-gnu, pushed to trunk
as obvious.

-- >8 --

The code path for non-dependent operator expressions rewritten from a
<=> returning a non-class type (added in r16-3727-gf2fddc4b84a843) is
also reached for a reversed such <=> expression with the form
0 @ (y <=> x) where the @ is <=>, so we need to relax the relevant
assert accordingly.

        PR c++/123601

gcc/cp/ChangeLog:

        * tree.cc (build_min_non_dep_op_overload): Relax
        COMPARISON_CLASS_P assert to accept SPACESHIP_EXPR too.

gcc/testsuite/ChangeLog:

        * g++.dg/lookup/operator-9.C: New test.
---
 gcc/cp/tree.cc                           |  3 ++-
 gcc/testsuite/g++.dg/lookup/operator-9.C | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/lookup/operator-9.C

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 030af4d219d1..ab9d0d532f54 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -3849,7 +3849,8 @@ build_min_non_dep_op_overload (enum tree_code op,
 
          if (TREE_CODE (non_dep) != CALL_EXPR)
            {
-             gcc_checking_assert (COMPARISON_CLASS_P (non_dep));
+             gcc_checking_assert (COMPARISON_CLASS_P (non_dep)
+                                  || TREE_CODE (non_dep) == SPACESHIP_EXPR);
              if (reversed)
                std::swap (op0, op1);
              return build_min_non_dep (TREE_CODE (non_dep), non_dep, op0, op1);
diff --git a/gcc/testsuite/g++.dg/lookup/operator-9.C 
b/gcc/testsuite/g++.dg/lookup/operator-9.C
new file mode 100644
index 000000000000..6c9326ec0503
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/operator-9.C
@@ -0,0 +1,17 @@
+// PR c++/123601
+// { dg-do compile { target c++20 } }
+
+#include <compare>
+
+struct A {
+  bool operator==(int);
+  int operator<=>(int);
+};
+
+template<class T>
+void f() {
+  A a;
+  (void)(0 <=> a);
+}
+
+template void f<int>();
-- 
2.53.0.rc0.25.gb5c409c40f

Reply via email to