<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54142>54142</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            -Wambiguous-reversed-operator is confusing
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          JVApen
      </td>
    </tr>
</table>

<pre>
    ````
// clang++ -std=c++20 -g -O3 -Wambiguous-reversed-operator t.cpp
struct C
{
    int m{0};
};

bool operator==(const C &lhs, const C &rhs)
{
    return lhs.m == rhs.m;
}

struct D
{
    C m;
    bool operator==(const D &rhs) { return m == rhs.m; }
};

bool f(D l, D r)
{
    return l == r;
}
````
[Code at compiler-explorer](https://compiler-explorer.com/z/8zoe799ss)

This code gives the following warning:
````
<source>:19:14: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'D' and 'D') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
    return l == r;
           ~ ^  ~
 <source>:14:10: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
    bool operator==(const D &rhs) { return m == rhs.m; }
         ^
````
Although this warning is technically correct, it is really confusing as it seems to indicate the problem lies with the 'use' of the `operator==` while the issue actually lies with the definition of the operator.
It would be much more logical that this warning would be flagging the definition instead of the use.
As such it would:
 - Also flag places where operator== ain't being used (yet)
 - Allow a fix-it which suggests adding the `const`
 - Point the user to the problem instead of staring at code that is actually 'correct' (in the sense that you don't have to adapt that code to get rid of the ambiguouty. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1VU2P4jgQ_TXhUgoKCRA4cOiGbmnmMivtavds4krilbEz_oBhfv2WnQ-gu6c1l0UhsV1xVb1Xr5yj5tddss5uV3ZIsqckf6ULKslUk-TPdEFqHU-KQ9VP8wzSBtJvBaT_sNNRNF57mxo8o7HIU92hYU4bcPOq63qf1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