Clang does not recognize nested class when used in a base class

Viewed 52

The following example does not compile in recent versions of clang, gcc versions work fine:

template<typename T>
struct Base{};

template<typename T>
struct Derived: public Base<typename Derived<T>::WrappedT>{
    struct WrappedT{};
};

int main(){

}

Live example on godbolt.

clang: error: no type named 'WrappedT' in 'Derived<T>'

For ordinary types, both compilers fail with a similar error as clang did, gcc complains about incomplete type.

template<typename T>
struct Base{};


struct Derived: public Base<Derived::WrappedT>{
    struct WrappedT{};
};

int main(){

}

Live example on godbolt.

Which compiler is correct? I suspect clang is correct and gcc works only due to some implementation details in two-phase name lookup for templates.

I know I can pull WrappedT outside but in my code there isn't only one T and this version would save me some typing and improve readability.

0 Answers
Related