Is this code valid C ++ (11)?
struct Base { template <typename> struct nested; }; struct Derived1 : Base { }; struct Derived2 : Base { }; struct Derived3 : Derived1, Derived2 { }; typedef Derived3::nested<int> xxx;
What i know
The above code does not compile with:
- Apple LLVM 5.0 (clang-500.2.75)
- Clang 3.4
But it successfully compiles with:
- gcc 4.9.0 20131110 (experimental)
- gcc 4.8
Also, if I change the nested type to a type without a template, i.e.
struct Base { struct nested; }; ... typedef Derived3::nested xxx;
then it works with the above compilers.
[edit] Changing the structure of a nested template to a template alias also does not change anything;
template <typename> struct dependent { struct type; }; struct Base { template <typename T> using nested = typename dependent<T>::type; };
gives the same results with the above compilers. [end edit]
From N3242 ยง10.1 [class .mi]
A class can be an indirect base class more than once and can be a direct and indirect base class. There are limited things you can do with this class. Non-static data members and member functions of a direct base class cannot be specified in the scope of a derived class. However, static elements, enumerations, and types can be explicitly mentioned.
I think this means the code must be valid, but I'm not sure.
c ++ gcc multiple-inheritance clang nested-class
Louis dionne
source share