Current C ++ compilers (the latest gcc, clang) require a keyword typenamein the example below:
template<class T>
struct A
{
};
template<class T>
void f(T)
{
struct C
{
};
typedef typename A<C>::Type Type;
}
If typenameomitted, gcc (4.9, 5.0) reports an error:
need 'typename' before 'A<f(T)::C>::Type' because 'A<f(T)::C>' is a dependent scope
This example is otherwise well-formed according to my reading of the C ++ 11 standard.
This behavior is apparently covered by the following wording:
[temp.dep.type] / 8
Type depends if it
template parameter
member of unknown specialization
a nested class or enumeration that is a member of the current instance,
cv-qual type, where the cv-unqualified type depends,
a composite type built from any dependent type,
, ,
-, , - , ,
decltype (), .
, [class.local], C , . , A<C> ?
, C :
template<typename T>
struct A
{
typedef T Type;
};
template<class T>
void f(T)
{
struct C
{
enum { value = T::value };
};
typedef typename A<C>::Type Type;
}
A<C> ?