The C++14 standard (N4296) says in 8.5/17.6.1
If the initialization is direct-initialization [...], constructors are considered. The applicable constructors are enumerated, and the best one is chosen through overload resolution. [...] If no constructor applies, or the overload resolution is ambiguous, the initialization is ill-formed.
Therefore in direct-initialization, only constructors are considered - conversion functions are ignored. In the following code there is no applicable constructor of A
, only a conversion function from B
. However, the code compiles, why?
struct A{};
struct B{
operator A(){ return A{}; }
};
int main() {
B b;
A a(b); // direct-initialization
}