<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57920>57920</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Ambiguous overloaded operator== in C++20: GCC compiles without error, while clang rejects
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bc-lee
</td>
</tr>
</table>
<pre>
Consider following code:
```c++
class Interface {
public:
virtual ~Interface() {}
virtual int type() const = 0;
virtual bool operator==(const Interface& other) const = 0;
bool operator!=(const Interface& other) const { return !(*this == other); }
};
template <int I>
class Implementation : public Interface {
public:
Implementation() : Interface() {}
~Implementation() override = default;
int type() const override { return I; }
bool operator==(const Interface& other) const override {
return type() == other.type();
}
};
int main() {
Implementation<1> a;
Implementation<2> b;
return a == b;
}
```
https://godbolt.org/z/5WqThjWMY
```
<source>:28:12: error: use of overloaded operator '==' is ambiguous (with operand types 'Implementation<1>' and 'Implementation<2>')
return a == b;
~ ^ ~
<source>:19:8: note: candidate function
bool operator==(const Interface& other) const override {
^
<source>:19:8: note: candidate function (with reversed parameter order)
1 error generated.
Compiler returned: 1
```
GCC compiles without error.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1VU2PmzAQ_TVwGW0EdoBw4JAlabWH3ipVPRqYJF45OLXNrra_vmMICdllt6tKjZwE2_Px_N6MqXTzUpS6tbJBAzutlH6W7R5q3WDA1xBEmyBan3_TaBh1wO796FdrJayFh9ah2YkaIcjOG3DqKiVrinKew5M0rhOKTLYX-4CtApb3Xtlmmu1qLlsH7uU0mtaE1kHANxAF_H7epdJagT6hEU4bMvWDrQbPSeoUtDugeS8qvIrD4k_Hye7BoOtMC97LA1-7g7QwYLmYUyq4npsebg_k8HhSwhGpvPQsPAR8e8M6beMRWyec1JSKj6R_To9b91EJCvKROtDLN-epn9AYqqOexQZ3olPujUKzYl49r7w93HIzK8jnhZ1mGGPBmGqCZ6rP4ro-KYkP5PJnOwrZTlibZ5qXVElbEJOwbyyYt6je8HeGLEakE4sLsLFPp54H507Wa8--0NjrptLKLbTZ0-w3fZMfv74fHn98-3nT8bPxeGl1Z4hmKka-prPydcx82RDFXpQ1dBZB73rSlRYNNhfJqB2yUbYMqCHEsZL7TnfUGmz1LN1hMG2bXhW_ms2S59291dw-G_a9bn9lDcYPVTUEybZ_mD1oTFWw9oeFVrv-cqwJgGx8f-66tu6T_5cy9eiSfwd1YdYghbekxkkYcUSCAdo0w0XUB48HCWGPrYeOzWJYL_XxJBWZDzxi4xPFH1Tb17KkE_VOFnxu3bkh9iLEIk5TnkfLeJWGTcGbnOcidNIpLNaXapipnbN2soVyeAGxyON4P1fASng-0DrQdUkvNYOPWDsbdkYVr_qB3LpqQWFootTT-Hd3Mtr70FRa26H1nZLlLAoPRc0xZTyt010Vs3SVNFG2rKIoytKK7Xi9DJWoUNkiSAgra_EZ-hD0HCSbUBYsYizKGY84T1m6qKJlmi-TJFmJOMccg2WEdJmohcfhGzU0RQ-p6vaWNpW0zl436XUg9y1in47ii46IMEVV3ynEsM9c9Mj_ALa4Vso">