As I understand, clause 16.6.2 applies here for the direct initialization of a
which considers only A
's constructors.
But the code compiles fine.
Which part am I missing that causes the user defined conversion functions to also be considered?
struct A {};
struct B {
operator A();
};
void f()
{
A a(B{});
}
A
has an implicit move and an implicit copy constructor, both of which take references to A
and the references in these parameters can be initialized by a call to the conversion operator in B
.
In the end, overload resolution will choose the implicit move constructor.
That being said, this causes an unnecessary move construction on A
which the compiler is not permitted to elide. The open CWG issue 2327 considers eliminating this unnecessary temporary object so that the conversion function can directly initialize the object and some compilers already handle it in some similar form (against the specification in the current standard).