I recently came upon this code:
struct Foo{};
int main()
{
Foo a;
// clang++ deduces std::initializer_list
// g++5.1 deduces Foo
auto b{a};
a = b;
}
It compiles fine with g++5.1, but fails in clang++ (used both -std=c++11
and -std=c++14
, same results). The reason is that clang++ deduces the type of b
as std::initializer_list<Foo>
, whereas g++5.1
deduces as Foo
. AFAIK, the type should indeed be (counter-intuitive indeed) std::initializer_list
here. Why does g++5 deduces the type as Foo
?
There is a proposal for C++1z that implements new type deduction rules for brace initialization (N3922), and I guess gcc implemented them:
Here is the gcc patch concerning the new changes with regards to "Unicorn initialization."