Possible gcc 3.4.4 bug.
Marco Manfredini
mldb@gmx.net
Sat Mar 12 00:55:00 GMT 2005
On Wednesday 09 March 2005 21:45, Phillip Neiswanger wrote:
> template <class T> class Base
> {
> public:
> int size() { return m_sz; }
> protected:
> int m_sz;
> };
> template<class T> class Derived : public Base<T>
> {
> public:
> int size() { return m_sz; }
> };
>
> The errors are as follows:
>
> pgn> g++34 t.cc
> t.cc: In member function `int Derived<T>::size()':
> t.cc:11: error: `m_sz' undeclared (first use this function)
> t.cc:11: error: (Each undeclared identifier is reported only once for each
> function it appears in.)
No bug here: gcc 3.4.+ implements the standard c++ two phase name lookup.
This error happens while the compiler parses Derived<T> -- at that moment
("Phase 1"), he has no idea what Base<T> contains, because this knowledge is
only available during instantiation of Derived<T> (Phase "2"). In "Phase 1"
the compiler looks at m_sz and sees, that it does not depend on any template
parameter, so the compiler decides that m_sz must have a meaning independent
from any binding of the template parameters (Suppose you would specialize
Base<int> to have no m_sz member to see what that means). If you prefix m_sz
with Base<T>:: or Derived<T>:: however, you turn m_sz into a depended name
for which semantic lookup is postponed onto "Phase 2".
--
Marco
More information about the Gcc-help
mailing list