This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/32762] New: Lost variable scope with template class that inherits from templated class using args of the first class
- From: "javimena at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Jul 2007 02:24:58 -0000
- Subject: [Bug c++/32762] New: Lost variable scope with template class that inherits from templated class using args of the first class
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I'm using gcc versión 4.1.2 (Ubuntu 4.1.2-0ubuntu4). I'm trying to compile this
relatively simple code, but it doesn't compiles. The compiler says (i
translated some phrases from spanish to english):
javimena@javimena-desktop:~/cppexamples$ g++ Example1.cc
Example1.cc: In constructor ?XRIVarArray<Float>::XRIVarArray(int)?:
Example1.cc:37: error: ?x? was not declared in this scope
The only file is Example1.cc:
--------------------------------------------------------
// line: 1
#include <cstdio>
template<class Float>
class XRIVar {
public:
Float min;
Float max;
};
template<class Var>
class VarArray {
protected:
Var* x;
public:
VarArray() {
x = 0L;
}
VarArray(int n) {
x = new Var[n];
}
Var& operator [](int n) {
return x[n];
}
};
template<class Float>
class XRIVarArray : public VarArray< XRIVar<Float> > {
public:
XRIVarArray(int n)
: VarArray< XRIVar<Float> >(n){
for (int i=0; i < n; i++) {
x[i].min = 2; // line: 37
x[i].max = 10;
}
}
};
int main() {
using namespace std;
XRIVarArray<double> xva(5);
printf( "%g\n", xva[1].max);
return 0;
}
--------------------------------------------------------
If I inherit from a class without template arguments, the there is no problem.
The workaround for now is to replace x[i] with this->x[i].
But I think this is still a bug.
--
Summary: Lost variable scope with template class that inherits
from templated class using args of the first class
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: javimena at gmail dot com
GCC build triplet: i486-linux-gnu
GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32762