The code follows.
struct A {
A() {}
};
struct B {
B() {}
explicit operator A() { return A{}; }
};
struct C {
A a;
C(B b) : a{b} {}
};
I have a struct A
which is not aggregate constructible (because it has a constructor defined). The same goes for struct B
. But it also has an explicit user-defined conversion operator to struct A
. Now struct C
's constructor takes a struct B
, and uses it to construct struct A
. As on cppreference, the conversion operator can participate in direct initialization, which I believe is the case for the member initialization of struct C
. It passes on GCC 5.2 (C++11). But however it fails on Clang 3.6. I tried with C++11, C++14, and C++1z.
If I change a{b}
to a(b)
, it passes on both Clang and GCC.
I wonder if it is a Clang bug or I misunderstood the standard?