typedef
does not need to appear before the type.
template <typename T>
struct S { typedef T type; };
template <typename T>
void f() { typename S<T>::type typedef t; }
This is perfectly valid, and in this case, I hope you can understand that parsing would be complicated if typename
were optional.
I can understand that
template <typename T>
void f() { typedef S<T>::type t; }
could be interpreted differently, but that would introduce unexpected cases where the position of the typedef
keyword suddenly becomes significant.