On 7/23/25 3:46 PM, Patrick Palka wrote:
As a follow-up to r16-2448-g7590c14b53a762, this patch attempts to teach
build_min_non_dep_op_overload how to rebuild all rewritten comparison
operators, not just != -> == ones, so that we don't incorrectly repeat
the unqualified name lookup at instantiation time.

Talking about mangling earlier made me wonder how we were handling non-dependent operator expressions, and indeed it seems we get it wrong since GCC 6:

struct A { };
A operator+(A,A);
template <class T>
void f(decltype(T(),A()+A())) { }
int main()
{
  f<int>(A()); // oops, mangles as operator+(A(),A()) instead of A()+A()
}

while clang and EDG corretly use the latter mangling.

With the current code I would think we could fix this by handling CALL_EXPR_OPERATOR_SYNTAX in mangle.cc, but your patch (and indeed the earlier one) would further obscure the original syntax.

While working on this I noticed we'll seemingly never create a rewritten
operator expression that is in terms of a built-in operator, since we
could have used a built-in operator directly in the first place, which
simplifies things.  I think this also means the extract_call_expr
handling of rewritten operators is wrong since it inspects for LT_EXPR,
SPACESHIP_EXPR etc directly, so this patch just removes it in passing.

That code is not about rewriting in terms of a built-in operator, it was to look through the operations added by the rewriting, e.g. TRUTH_NOT_EXPR for operator!= to !(operator==) to find the actual call to the operator underneath.

It does look like that's unnecessary now because build_new_op calls extract_call_expr before adding those decorations, so I don't object to removing it, but please make that a separate patch.

Jason

Reply via email to