<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58520>58520</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
CLang choosing copy constructor over initializer_list
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lkattha
</td>
</tr>
</table>
<pre>
The following short program returns '3' with clang, but '30' with GCC and '12' with MSVC.
The issue is that in lines (3) and (4), both the copy-constructor (1) and the initializer_list constructor (2) could be called.
According to cppreference.com, (2) should be called.
However, clang chooses (1) on both instances. (Interestingly, MSVC chooses (2) on (3) and (1) on (4).
This error also accurs if the constructor of S takes an initializer_list of another type T, which can be implicitly contructed from S, this is how I encountered the bug in real code.
```
#include <initializer_list>
struct S {
S() = default;
S(const S& other): i_(1) {} // (1)
S(const std::initializer_list<S> args): i_(10) {} // (2)
int i_;
};
struct T {
//Clang: calls (1)
//GCC, MSVC: calls (2)
T(const S& s) : s_{s} {} // (3)
S s_;
};
int main() {
S s;
T t(s);
//Clang, MSVC: calls (1)
//GCC: calls (2)
S s2{s}; // (4)
return t.s_.i_ + 2*s2.i_;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VU2TojAQ_TVw6RoKAioeODjOujtVuyetvVohBMlOTKwkjOX--u2AqKizVFRM-uO910mn1NWp2DQcai2lPgq1A9to4-Bg9M7QPRjuWqMsBGSW4geOwjXAJFW7gCyhbF23El-Wvi-XQFXlZxNymf21_r2MgvgtiBc-mbC29d_gGupAKJBCcZ8jxxzzs3-e4XuXRGMEh25MH04vTCvrTMucNt4oGRy8gVDCCSrFX262UlgHd8bEGzPdygpKDEel5NUZ1oIxbSrP32lgh4PhNTdcMR4xvfcoBneU55n_D33kn9x4y04dYI3WtifVYdSqJyIQEcW4NvJL78phGuswsTx5Z6_UrS85-95pk1ynvUxnEIPCqCw3BjlTaTVQxlpjQdRnEa-S6BrW4OgHpqLqUT1cpgoxcwPudOCw8QCPjWC4A9AeJRD7gxRMOHnycbuwvILa6D2svbHzUHA0-gjvgHLqtiPcl6tsd774hlOJ7hUfsQim8Xn0f0kqFJNtxSFIl_dQg_TbrW9PELkFs9d-BvBBRLmXLUjfoOI1bSX63a136vi3KXTE_RZMFyC2g-Y-4uwNdV_hGCrxLIZ1FXrieMS6XCNeoGZnR-Hjp_HJJf41i1DO-wzg0eH6fivAZixAH3TZHV7M6vevfaTQW-E5HrbjyJaMbDdjyWwv7wLsFhPbjkjPp3-urNInrNbe7WtOnvSeCjVUcVRaTH1byg04NOvlfb3PcyvDA8X_6fG1DpifnBljQnigmz2h23dWcJHdRmKLVq-AQReWRHelHR-HkBfJdDpNM5Jks7Aq0mqezmno8BDyYvnz0np8K_MNc3zgsUU9nPOwNbJonDtYv2E7zDts2m3Zt76VlJ_DzwteC384Q3FXXQ9HhVeTfELisCnKdJrOy7icpTThjGVZPs9LMmXZLK8mZV6HkpZc2iKYvAaEKH7srwF8DyZvoShITEgS48izeTyLsrSeTzhLqjqb1qxOgizmWH4ZeRyRNrvQFB0k7CIWFz0Te12k1oqd4rxLh_Fp6_BeK-QHdXjphF3qooP-DytWA48">