<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/89079>89079</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang++] Clang fails to call initializer_list constructor in specific cases
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidkjaer
</td>
</tr>
</table>
<pre>
There seems to be a very specific case where clang does not call an initializer_list constructor even though it should apply.
The issues arises when the class `Foo` has an `std::initializer_list<Foo>` constructor and you create an object like this`Foo f{Foo{}};`:
```
#include <initializer_list>
#include <iostream>
#include <vector>
class Foo
{
public:
Foo()
{
}
explicit Foo(std::initializer_list<Foo> l)
{
std::cout << "Initializer list constructor\n";
}
void hi()
{
std::cout << "Hello\n";
}
};
int main() {
Foo other;
Foo f{std::move(other)};
f.hi();
}
```
When compiled with clang 18.1 the above example prints:
**Hello**
On both gcc and msvc the example prints:
**Initializer list constructor
Hello**
If I switch the initialization to `Foo f{{std::move(other)}}` or `Foo f{Foo{}, Foo{}}` clang correctly calls the initializer_list constructor.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU2PozgQ_TXmUpoIzPeBQyeZaPu0l5H2uDKmEmrGYGQberK_fmWTzUdvd2Yii4Apv_dcVD0La-k0IjYs37J8H4nZ9do0nVio-_FdoIla3Z2bbz0aBIs4WHAaWgQBC5oz2AklHUmCFBbhLYRJJcYTdBotjNqBFEqBGIFGciQU_YPmb0XWgdSjdWaWThvABUdwvZ5PPZAD2-tZdSCmSZ03LN6z-OVbj0DWzmhBGLJoPZtfEwitBVbEB61ZEUMvrCdkRWxdx9IXlr68J2fpzgenX338vRAxdnDWM0iDwqGH0e13lA4U_UBwPdmVB46s3HqIcsvKvR_plhWxZwtyL9civoz1kac0SjV3CCzd_V_T1w_DtHUGxfDJ6wW97tvLcF0z4uWtk-V2vZnmVpG8igSAEMQrxuvb1DV8fdjfI_sp_DkpkuQua3-dZFCf4_vfFUHq2flNsXQHjPPXGyC8LxmW70bGuU_7M62Lpg56etjib_P_gUrp50Trh78jpdHBIGhcGR-5fN1o16N5APuvmq4qBr0g49Uayet7Djhurpu58l7FvKu2cP3Ld4nUw0QKO3gj118aNKk2SWgf0eoFAX-KYVIIk6HR2Vsdcz_WRITbe-w_R2i16-EkZWicwS4yQD4Fe_pVQ9wndK9HeAX7Rk72geVab8KRHr0x3fXmLxJa7n3nawMftjPfwUNve5MISZPaGJROnYOt2UcZHxjbJuqatKvTWkTYJGWSpkVWpknUN1VSZF3VVaKu82OHvDuKFpNYxMc0x7IoImp4zLM4S8okS6s83mQpz_I6LkqZYJtVFctiHASpjVLLsNHmFAV_bKo6LutIiRaVDb7OeRDvizjfR6bx8V_a-WRZFnvB9obgyKlwGFxWbP3I97ALuz8KUuEACJ7-1NBpfDwbbDQb1fTOTaEc-IHxw4lcP7cbqQfGD17C5e_LZLT3XMYPq-Mzfgib-jcAAP__dpUAUg">