After being confused why my code gave me an ambiguity error on GCC but no errors on Clang, I simplified the code. It can be seen below.
struct Foo
{
// Foo(F
My best guess after some digging: I get the same error with the following code:
struct Foo { Foo(int*) {} };
struct Bar {
operator Foo(); // { return Foo{nullptr}; }
/* explicit */ operator int*();
};
int main() { Foo f{Bar{}}; }
And, when I uncomment the commented code, then the problem disappears. It seems to me that, in OP's original templated version, when implicit conversion is required from Bar
to Foo
, GCC only "instantiates" conversion operator declarations and then resolves overload before instantiating of their bodies.
As for why explicit
helps, it is because in the second case, there is one more conversion required (Bar
→int*
and then int*
→Foo
).