c++/9558: subclass cannot find parent members without explicit "this->" in some cases
Wolfgang Bangerth
bangerth@ticam.utexas.edu
Tue Feb 4 00:48:00 GMT 2003
> Surely there's got to be some consideration for backwards compatibility,
> if not real world issues?
Just to prove my point about surprising behavior:
-----------------------------------------------
#include <iostream>
// ---------
const int N = 2;
// ---------
template <typename T> struct A { // templated base class
static const int N = 1;
};
template <typename T> struct B : A<T> {
B () { std::cout << "N=" << N << std::endl; }
};
// ---------
struct C { // non-templated base class
static const int N = 1;
};
template <typename T> struct D : C {
D () { std::cout << "N=" << N << std::endl; }
};
// ---------
int main () {
B<int> b;
D<int> d;
}
---------------------------------------------
In each case, the question is: which N to take, the one from the base
class, or the global one. Here are a couple of data points:
gcc2.96:
N=2
N=1
present gcc CVS:
N=2
N=1
Intel icc7:
N=1
N=1
Intel icc7 with -Xc -ansi:
N=2
N=1
Compaq cxx:
N=1
N=1
So, what is right and what is wrong? And what is the "real world" you
quote?
W.
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@ticam.utexas.edu
www: http://www.ticam.utexas.edu/~bangerth/
More information about the Gcc-bugs
mailing list