<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/122579>122579</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Incorrect Diagnostic Message for Ambiguous Overloaded Operator in Clang
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wangbo15
</td>
</tr>
</table>
<pre>
Given the following code:
```
#include<iostream>
struct operand
{
int x;
operator int (){return x;};
operator bool() {return true;};
operator char() {return 'c';};
};
bool bar (operand i, operand j)
{
bool tst = (i == j);
return tst;
}
int main(){
operand o1{1}, o2{0};
std::cout<<bar(o1, o2);
}
```
Clang rejects it with the diagnostic, which dose not make sense, because there is no `float` in the source code:
```
<source>:12:17: error: use of overloaded operator '==' is ambiguous (with operand types 'operand' and 'operand')
12 | bool tst = (i == j);
| ~ ^ ~
<source>:12:17: note: because of ambiguity in conversion of 'operand' to 'float'
<source>:5:3: note: candidate function
5 | operator int (){return x;};
| ^
<source>:6:3: note: candidate function
6 | operator bool() {return true;};
| ^
<source>:7:3: note: candidate function
7 | operator char() {return 'c';};
| ^
<source>:12:17: note: because of ambiguity in conversion of 'operand' to 'float'
12 | bool tst = (i == j);
| ^
<source>:5:3: note: candidate function
5 | operator int (){return x;};
| ^
<source>:6:3: note: candidate function
6 | operator bool() {return true;};
| ^
<source>:7:3: note: candidate function
7 | operator char() {return 'c';};
| ^
<source>:12:17: note: built-in candidate operator==(float, float)
12 | bool tst = (i == j);
```
Moreover, MSVC's output seems correct:
```
example.cpp
<source>(12): error C2593: 'operator ==' is ambiguous
<source>(12): note: could be 'built-in C++ operator==(int, int)'
<source>(12): note: or 'built-in C++ operator==(int, bool)'
<source>(12): note: or 'built-in C++ operator==(int, char)'
<source>(12): note: or 'built-in C++ operator==(bool, int)'
<source>(12): note: or 'built-in C++ operator==(bool, bool)'
<source>(12): note: or 'built-in C++ operator==(bool, char)'
<source>(12): note: or 'built-in C++ operator==(char, int)'
<source>(12): note: or 'built-in C++ operator==(char, bool)'
<source>(12): note: or 'built-in C++ operator==(char, char)'
<source>(12): note: while trying to match the argument list '(operand, operand)'
cl : Command line warning D9002 : ignoring unknown option '-std=c++20'
Compiler returned: 2
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUV8GO2zgM_RrlQszAlus4OeSQOJ3FHooeFti7LDOOWlsMJHnSufTbF5TtJJ1Ju5kCWWADY6yRKD7ykaYo5b1pLOJK5BuRb2eqD3tyq6OyTUVpPquofln9YZ7RQtgj7Kht6WhsA5pqFNlaJPGZJ-OTrIXMjNVtz8ulIR8cqk5kH0Wy9sH1OgAd0Clbs2yxEckawNgA30QW_4mrgVycFHIh5FIUG4ehd3YQKraj6Fm2ImoHWTgLB9fjT-T1Xrk38kIWWsjicst5kKwZAyrl2KjRBTBClpM_8IVNPTsV5YMPILIt7zE84HGUGy2aTPXhDBjR2PtOGXtiIIrDCYxSUWxSFmcLpCg2ydlRH2qOTbbW1AeRlSIrq-gwpaP4ZMGIdxm_ZF22yjbg8Avq4MEEOJqwj_GvjWos-WA06znujd5DTR7BEpv7FcGj9ciLFWrVe-RtDsF4sARinuxaUkHMEzBDRnnqncYpneBKPmXlIMM5lK1TyX8KlkXnyPGAYWgH9IyuJVVjfQ50jCezLmTBRqiuMk1PveeIRLcmQsPLAXm2mNJTFsDzP8wMEQaAVIIoSrgxyvwbxC9_30HkHwG-_9JJSyESM9FJu9EHE16YQ032GZ03ZHnpR_MD8cTAuCzewuQiW2eXIFrZ2tQqIOx6q4MhO5qfj-a_5-M8Oy3yj2_B5zeDz1-D3_i1TwZchS9uhi9ew99aPP6VgnuF-bfz86qV_6ss-d0c-Qn8f5olN-dIb9rwwElxMmZCnWrdYsyGEsbBj2XrhqR4dSR8IodcX1nlp7_-LoUsPFAfDn0Aj9h50OQc6jD2BBe78ZvqDi0-6sPhtXtykQ5H0VjMoZT5Mv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