Please see the following code:
struct base {};
template <class T>
struct derived : T {
using base_type = T;
using base_type::T;
};
int main()
{
derived<base> x;
}
GCC accepts this code, but Clang and MSVC reject it. Who is right and why?
using base_type::T;
is a declaration, and the using
before it is an alias. This is a bit of an edge case in the standard, since the real question boils down to where does the T
get expanded. The C++ committee was referenced here as saying that they did not intend for that syntax to be valid, so LLVM explicitly removed it. It doesn't look like there's anything in the standard preventing it, so gcc isn't incorrect in allowing the conversion. Who is 'correct' is up to you.