template member variable bug in gcc 3.4?
Dyer, Christopher
cdyer@amazon.com
Wed Apr 21 01:01:00 GMT 2004
I've got a question for the c++ experts on this list regarding an unusual coding construct that is failing to compile under gcc 3.4 but works under 3.2.
(Code sample is below). I've got a templatized class that derives from a class templatized on the same type T. This base class defines a protected member variable t_ of the type T*. In the derived class, referencing t_ without any scope produces "error 't_' undeclared (first use this function)" in gcc 3.4, but works just fine in gcc 3.2.
I can work around this by explicitly naming the base class and using the scope resolution operator or by prefacing the member variable name with this->.
Can someone explain to me whether this is a compiler bug or an aspect of C++ syntax that I don't understand?
Thanks for any insight,
Chris
-------------code sample-----------------
class foo {
public:
int position() const { return 1; }
};
template <class T> class driver {
public:
virtual ~driver() { delete t_; }
driver(T *t) : t_(t) {}
protected:
T *t_;
};
template <class T> class wrapper : public driver<T> {
public:
wrapper() : driver<T>(new T()) { }
// the following line compiles in GCC 3.2, but not in GCC 3.4.
int position() const { return t_->position(); };
// to make it work, it must be changed to one of the following
// (compiles in both GCC 3.2 and 3.4)
// int position() const { return driver<T>::t_->position(); };
// int position() const { return this->t_->position(); };
};
int main() {
wrapper<foo> test;
return 0;
}
More information about the Gcc-bugs
mailing list