<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68123>68123</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang invokes explicit conversion operator when assigning to const ref of target type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
muggenhor
</td>
</tr>
</table>
<pre>
[Example](https://godbolt.org/z/Gsox1fhjx):
```cpp
struct T {};
struct U { explicit operator T() const; };
void f(const U& x) {
const T& y(x); // <-- this is *not* an initialization of `T` but const-ref to `T`
}
```
I expect only *implicit* conversions to be allowed for intialization of `y` there. And GCC agrees (see godbolt link). Clang accepts this though.
When declaring a converting constructor instead Clang also agrees (and is thus inconsistent), [example 2](https://godbolt.org/z/KcsxGvzoP):
```cpp
struct U {};
struct T {
explicit T(const U&);
};
void f(const U& x) {
const T& y(x); // <-- this is *not* an initialization of `T` but const-ref to `T`
}
```
TLDR: for initializing of local (const?) references clang considers explicit conversion operators (but not explicit constructors) while it shouldn't.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVE2P6jYU_TWXzRUo2CSQRRZ8lFHVLqqKUdfGuUn8nrGRfcPA_PrKCbxhXtVqtpWiRLHvxzn3HFvFaFpHVEG-gXw3UT13PlSnvm3JdT5Mjr6-pc1frup0tgT5DsSqYz5HkGsQexD71tdHb3nmQwti_w5i_xL9dd50364gyhSW7SBbQ5GNjz6fx5XIodeMB4TlBpY7kJtP669pHel6tkYbRn-moNgHPIBYgShRexcZ5Aafc8f3xZsaGxCrIQZfQRSYwAydhggc01OxAm8gViPWDY6cEOR2OkXuTEQTEcTaeQaxRuXQOMNGWfOu2HiHvkEosgMUGR57HstOAzXI_rFxh7bc_TSJZ8i_JqakGb2zt9TQnEbiqav27kIhGu9iKnskVNb6N6qx8QGN-yeeW8LDHQWa4drV-LLdomoDUSKzikR4lw2tcd9BlDPcWuVaVFrTmeNInTvft93sGedfHTmsSVsVTAq_Y-P0M3BP2g2gIpOqH1Vt9E_9latxKN9HNC6lmcjkOGkgtgj5hka_ofia437T8fpyefd_fMlxr__iuMOzP34Y7_DJR6NNPhT93xvv8PvuT5Dru5PuHZKavkHrtbL4oANyn6gEaiiQ0xRRD-IO-tUU4sfMPgz749wOwiegzvOnwIdlYir-1hlLaBhj53tbOxBLnk3qStalLNWEqnlRFnJRLmU-6So5L-ZLTceF1HlWKjkvSqImz1dNIbUq5cRUIhNynmUpMpfZLDvqclFQo_JSi3pRwCKjkzJ2Zu3llAw1MTH2VBWruZATq45k4-NyDFUKmh77NsIisyZy_Ehjw5aq0e3GXfx3-u9x4Fs6SOP9m6bN_m6MpKBvkFVoiZFvZ5r0wVY_nQDDXX-caX8CsU8Y7p_pOfhvpBnEfuARQewHKn8HAAD__2sk02I">