In the source at the point of the first error messages: typedef typename std::allocator<T>::size_type st1; typedef typename size_type st; typedef size_type st2; the first typedef works but the second two do not even though the class is derived from std::allocator<T>. In simple cases, e.g.:class A{ public: typedef int B; }; class C : public A { public: B b; }; the derived class can inherit the types of the base class, but not here. Sticking in a "typename" doesn't help.
Created attachment 6334 [details] Compiler output (-v -save-temps)
Created attachment 6335 [details] Source code (-save-temps)
This is equivent to: template <class T> class A { typedef int t; }; template <class T> class B: A<T> { typedef t t1; }; Which is invalid as t is not dependent so it needs to be declare not in the subclasses. The fix would be to declare t1 as "typedef A<T>::t t1;" Also one the mainline I get the following note: pr15534.ii:31253: error: `size_type' does not name a type pr15534.ii:31253: note: (perhaps `typename std::allocator<_CharT>::size_type' was intended)
Comment three says the original example was invalid: "Which is invalid as t is not dependent so it needs to be declare not in the subclasses". So here is a different example where "t" *is* dependent, and it fails too. template <class T> class A { typedef T* t; }; template <class T> class B: A<T> { typedef t t1; }; or am I not understanding what you mean by dependent? g++3.4.0 gives: foo.cc:8: error: `t' does not name a type foo.cc:8: error: (perhaps `typename A<T>::t' was intended) Ivan
You misunderstand. Type-dependent expressions (From 14.6.2.2 P3): Anid-expressionis type-dependent if it contains: —an identifier that was declared with a dependent type, —a template-id that is dependent, —a conversion-function-id that specifies a dependent type, —a nested-name-specifier that contains a class-name that names a dependent type.
In your example, ------ template <class T> class B: A<T> { typedef t t1; }; ------ you reference the name 't'. Since 't' does not depend on the template argument 'T', it is non-dependent and needs to be looked up at the time of declaration of the template. However, since name lookup does not look into template dependent base classes such as A<T> it doesn't find anything. The solution is to make sure that 't' is qualified as dependent, for example by writing 'typename A<T>::t'. This is really no different than all the other name lookup things that we believe are well-documented in the non-bugs and changes-in-3.4 sections of our web pages. Please review these if you are unsure. W.