]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: extract_call_expr and C++20 rewritten ops
authorPatrick Palka <ppalka@redhat.com>
Thu, 7 Aug 2025 19:43:22 +0000 (15:43 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 7 Aug 2025 19:43:22 +0000 (15:43 -0400)
After r16-2519-gba5a6787374dea, we'll never express a C++20 rewritten
comparison operator as a built-in operator acting on an operator<=>
call, e.g. operator<=>(x, y) @ 0.  This is because operator<=> always
returns a class type (std::foo_ordering), so the outer operator@ will
necessarily resolve to a non-built-in operator@ for that class type
(even in the non-dependent templated case, after that commit).

So the corresponding handling in extract_call_expr is basically dead
code, except for the TRUTH_NOT_EXPR case where we can plausibly still
have !(operator==(x, y)), but it doesn't make sense to recognize just
that one special case of operator rewriting.  So let's just remove it
altogether; apparently it's no longer needed.

Also, the handling is imprecise: it recognizes expressions such as
0 < f() which never corresponded to a call in the first place.  All
the more reason to remove it.

gcc/cp/ChangeLog:

* call.cc (extract_call_expr): Remove handling of C++20
rewritten comparison operators.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/call.cc

index 9283d974966c0debc755e18fae3221a4e201abe3..63cad2aca4ca5ece8174501743a81a121e3a6657 100644 (file)
@@ -7904,28 +7904,6 @@ extract_call_expr (tree call)
     call = TREE_OPERAND (call, 0);
   if (TREE_CODE (call) == TARGET_EXPR)
     call = TARGET_EXPR_INITIAL (call);
-  if (cxx_dialect >= cxx20)
-    switch (TREE_CODE (call))
-      {
-       /* C++20 rewritten comparison operators.  */
-      case TRUTH_NOT_EXPR:
-       call = TREE_OPERAND (call, 0);
-       break;
-      case LT_EXPR:
-      case LE_EXPR:
-      case GT_EXPR:
-      case GE_EXPR:
-      case SPACESHIP_EXPR:
-       {
-         tree op0 = TREE_OPERAND (call, 0);
-         if (integer_zerop (op0))
-           call = TREE_OPERAND (call, 1);
-         else
-           call = op0;
-       }
-       break;
-      default:;
-      }
 
   if (TREE_CODE (call) != CALL_EXPR
       && TREE_CODE (call) != AGGR_INIT_EXPR