c++/9558: subclass cannot find parent members without explicit "this->" in some cases
Wolfgang Bangerth
bangerth@ticam.utexas.edu
Tue Feb 4 02:43:00 GMT 2003
> After thinking about it, (and based on the initial response of "can we
> add this as a FAQ to non-bugs"),
...which I just took care of...
> perhaps the problem is in the error
> message more than the behaviour. My assumption was this was a problem in
> the new parser and that it wasn't resolving because something had
> confused it. Is there a way to differentiate between this and a variable
> that absolutely positively does not exist, and issue a different error
> message? I think that would at least stop more incorrect bug reports on
> the issue.
It's hard to come up with something reasonable, because of cases like
template <typename T> struct A { int i; };
template <typename T> struct B : A<T> { int f() {return i;} };
template <> struct A<int> { }; // oops
In B::f, what is the compiler supposed to tell you? I guess one would like
to have something like
Error: "i" undeclared (did you mean "this->i" or A<T>::i"?)
The gotcha comes in the specialization of A<int>: there really is no "i"
in this class.
There are worse cases, like
template <typename T> struct B : typename A<T>::some_typedef {...};
where you really have no idea what the base class might be, unless you
actually instantiate it.
Of course, this doesn't mean that Mark or someone else has ingeneous ideas
for warnings...
W.
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@ticam.utexas.edu
www: http://www.ticam.utexas.edu/~bangerth/
More information about the Gcc-bugs
mailing list