The following program was constructed to abuse some peculiarities of two-phase lookup in gcc/msvc. It compiles fine with both gcc/msvc and clang but results in different return value from function g
:
struct A;
struct C {};
struct D {
D (const A &);
};
struct B {
void f (const C&,int){x=0;};
void f (const D&,char){x=1;};
int x;
};
template<typename T>
int f(const A &y)
{
B x;
x.f(y,0); // Line 18
return x.x;
}
struct A
{
operator C () const;
};
int g (const A&x)
{
return f<int>(x);
}
https://gcc.godbolt.org/z/pqAVsU
Both GCC and MSVC call A::operator C
and return 0, while Clang calls D(const A &)
and returns 1.
Is it true according to the standard that clang is right and call on line 18 should be resolved while struct A
is not yet declared or is this the case of unspecified behavior?