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 fails to 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 non-template type, i.e.
struct Base {
struct nested;
};
...
typedef Derived3::nested xxx;
then it works with the above compilers.
[edit]
Changing the nested
template struct 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;
};
produces 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 an indirect base class. There are limited things that can be done with such a class. The non-static data members and member functions of the direct base class cannot be referred to in the scope of the derived class. However, the static members, enumerations and types can be unambiguously referred to.
I think it means that the code should be valid, but I'm not sure.