This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11694] New: Template member class of template class mix-up
- From: "cholm at nbi dot dk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Jul 2003 13:55:18 -0000
- Subject: [Bug c++/11694] New: Template member class of template class mix-up
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11694
Summary: Template member class of template class mix-up
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cholm at nbi dot dk
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
Hi GCC developers,
I think I stumbled on a bug in G++. It has to do with template nested classes
in template classes. It seems that there's something missing in the parse.
Maybe it has something to do with the `second template pass bug'?
Please find the file `baz.cc' below.
prompt> g++-3.2 baz.cc -o baz
g++-3.2 baz.cc -o baz
baz.cc: In instantiation of `bar<double>':
baz.cc:47: instantiated from here
baz.cc:20: internal error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
My machine is a dual Intel Celeron, running Linux 2.4.18 SMP, with
GLibC version 2.2.5-11. The distribution is Debian GNU/Linux 3.0
(woody) with some extra packages from testing (sarge).
GCC is:
prompt> gcc-3.2 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.2/specs
Configured with: ../src/configure -v --enable-
languages=c,c++,java,f77,proto,p
ascal,objc,ada --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info -
-with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib -
-
enable-nls --without-included-gettext --disable-__cxa_atexit --enable-java-
gc=bo
ehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.2
Note, that the `baz.cc' file compiles fine with Intel C++ version
7.0.
If I change the source, so that the `bar' class takes two template
parameters, like:
template <typename A, typename B=A>
struct bar : public foo<A, B>
{
typedef foo<A , B> base_type;
typedef base_type::helper<1> helper_type;
helper_type _help;
bar(const A& a) : base_type(a, a), _help() {}
virtual int doit() { return _help.doit(_a,_b); }
};
it compiles fine.
If I in the `baz' class changes the definition of `helper_type' to
directly reference the sub-class of `foo<A,B>', like:
template <typename A>
struct baz : public bar<A>
{
typedef bar<A> base_type;
typedef foo<A,A>::helper<1> helper_type;
helper_type* _helper;
baz() : base_type(42) { _helper = new helper_type(2); }
int doit() { return _helper->doit(_a,_b); }
};
then I get:
> g++-3.2 baz.cc -o baz
bar.cc: In constructor `baz<A>::baz() [with A = double]':
bar.cc:50: instantiated from here
bar.cc:36: invalid use of undefined type `struct foo<double, B>::helper<1>'
bar.cc:6: declaration of `struct foo<double, B>::helper<1>'
bar.cc: In member function `int baz<A>::doit() [with A = double]':
bar.cc:51: instantiated from here
bar.cc:37: no matching function for call to `foo<double, B>::helper<1>::doit(
double&, double&)'
Again, Intel C++ version 7.0 compiles that just fine
Only if I instancises `foo<A,B>::helper<C>' with explicit types for
`A' and `B', like:
template <typename A>
struct baz : public bar<A>
{
typedef bar<A> base_type;
typedef foo<double,double>::helper<1> helper_type;
helper_type* _helper;
baz() : base_type(42) { _helper = new helper_type(2); }
int doit() { return _helper->doit(_a,_b); }
};
can I get an error free compile
The contens of `baz.cc' follows below:
//====================================================================
template <typename A, typename B>
struct foo {
template <int C>
struct helper
{
helper() {}
int doit(const A& a, const B& b) { return C + int(a) + int(b); }
};
A _a;
B _b;
foo() : _a(0), _b(0) {}
foo(const A& a, const B& b) : _a(a), _b(b) {}
virtual int doit() { return 0; }
};
//====================================================================
template <typename A>
struct bar : public foo<A, A>
{
typedef foo<A , A> base_type;
typedef base_type::helper<1> helper_type;
helper_type _help;
bar(const A& a) : base_type(a, a), _help() {}
virtual int doit() { return _help.doit(_a,_b); }
};
//====================================================================
template <typename A>
struct baz : public bar<A>
{
typedef bar<A> base_type;
typedef typename base_type::helper_type helper_type;
helper_type* _helper;
baz() : base_type(42) { _helper = new helper_type(); }
int doit() { return _helper->doit(_a,_b); }
};
//====================================================================
int
main(int argc, char** argv)
{
foo<double, double> foo(3.14, 42);
bar<double> b1(3.14);
int a1 = b1.doit();
baz<double> b2;
int a2 = b2.doit();
return 0;
}
//
// EOF of `baz.cc'
//
Yours,
___ | Christian Holm Christensen
|_| | -------------------------------------------------------------
| | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91
_| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91
_| Denmark Office: (+45) 353 25 305
____| Email: cholm@nbi.dk Web: www.nbi.dk/~cholm
| |