Consider this simple type:
struct A { A(int, int, int) {} A(std::vector<int>) {} };
The above snippet is a poorly formed program, since overload resolution fails because {1, 2, 3} can be used to initialize temporary A , so the c'tor copy is also viable to initialize A
Initially it was assumed that to solve the problem, you can use the marking of the first c'tor as explicit A(int, int, int) . And Klang agrees . On the other hand, the GCC still does not accept it , stating the same reason for the two viable c'tors.
To make matters worse, this is even more confusing for another observation. If list initialization was used instead, i.e. A a{{1,2,3}}; , then suddenly Clang and GCC accept the code with the initial definition of the class without changes (where there is nothing explicit ).
Which compiler is compatible with A a({1,2,3}); ?
c ++ language-lawyer
Storyteller
source share