This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15552] New: template inheritance does not recognize member variables
- From: "ziv at kashya dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 May 2004 09:02:14 -0000
- Subject: [Bug c++/15552] New: template inheritance does not recognize member variables
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I have a simple c++ file (no header files) that compiles well with g++ 3.0.2
and also, the original code (before simplification) that caused errors compiles
on the 3.3 series. The file has a template class with a public member function
and a derivative class. The derivative class does not recognize the member
variable.
The gcc version is 3.4.0 compiled on Linux
The c++ file is (note that it does not use ANY headers)
template<class A>
class Base {
public:
Base(const A& a_ber) {};
virtual ~Base();
A m_ber;
};
template<class A>
class Der : public Base<A> {
public:
Der(A a_ber): Base<A>(a_ber) {};
void memFunc();
void memFunc2();
};
template<class A>
void Der<A>::memFunc()
{
A temp = m_ber;
}
template<class A>
void Der<A>::memFunc2()
{
A temp = Base<A>::m_ber;
}
int main(int argc,char**argv) {
Der<int> x(3);
x.memFunc();
x.memFunc2();
}
=========================================================
The .ii file is:
# 1 "jojo.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "jojo.cc"
template<class A>
class Base {
public:
Base(const A& a_ber) {};
virtual ~Base();
A m_ber;
};
template<class A>
class Der : public Base<A> {
public:
Der(A a_ber): Base<A>(a_ber) {};
void memFunc();
void memFunc2();
};
template<class A>
void Der<A>::memFunc()
{
A temp = m_ber;
}
template<class A>
void Der<A>::memFunc2()
{
A temp = Base<A>::m_ber;
}
int main(int argc,char**argv) {
Der<int> x(3);
x.memFunc();
x.memFunc2();
}
=========================================
And the compiler output is:
ziv-lnx:~/temp/logger> /tmp/cross/local/bin/g++ -v jojo.cc -save-temps
Reading specs from /tmp/cross/local/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: ./configure --prefix=/tmp/cross/local --enable-languages=c,c++
Thread model: posix
gcc version 3.4.0
/tmp/cross/local/libexec/gcc/i686-pc-linux-gnu/3.4.0/cc1plus -E -quiet -v -
D_GNU_SOURCE jojo.cc -mtune=pentiumpro -o jojo.ii
ignoring nonexistent directory "/tmp/cross/local/lib/gcc/i686-pc-linux-
gnu/3.4.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/tmp/cross/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0
/tmp/cross/local/lib/gcc/i686-pc-linux-
gnu/3.4.0/../../../../include/c++/3.4.0/i686-pc-linux-gnu
/tmp/cross/local/lib/gcc/i686-pc-linux-
gnu/3.4.0/../../../../include/c++/3.4.0/backward
/usr/local/include
/tmp/cross/local/include
/tmp/cross/local/lib/gcc/i686-pc-linux-gnu/3.4.0/include
/usr/include
End of search list.
/tmp/cross/local/libexec/gcc/i686-pc-linux-gnu/3.4.0/cc1plus -fpreprocessed
jojo.ii -quiet -dumpbase jojo.cc -mtune=pentiumpro -auxbase jojo -version -o
jojo.s
GNU C++ version 3.4.0 (i686-pc-linux-gnu)
compiled by GNU C version 3.4.0.
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64211
jojo.cc: In member function `void Der<A>::memFunc()':
jojo.cc:21: error: `m_ber' undeclared (first use this function)
jojo.cc:21: error: (Each undeclared identifier is reported only once for each
function it appears in.)
Exit 1
====================================================
Note that if you comment out the line in memFunc, it compiles well. Also
memFunc2 has no problems.
--
Summary: template inheritance does not recognize member variables
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ziv at kashya dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15552