This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ internal compiler error, concerning templates
- To: bug-gcc at gnu dot org
- Subject: g++ internal compiler error, concerning templates
- From: Gerd Sussner <Gerd dot Sussner at informatik dot uni-erlangen dot de>
- Date: Mon, 14 Feb 2000 10:06:41 +0100
hi folks,
i discovered a bug in g++ concerning templates. i reduced my code to
the minimum amount to cause g++ exit with internal compiler error.
the bug occurs in gcc-2.95.2 and also in the latest snapshot-release
egcs-20000207. it occurs on i386-linux and irix-6.5 systems, other
systems were not tested since i don't have access. furthermore, i didn't
find any former announcement of this kind of a bug.
in my opinion, the code is absolutely correct c++-code, so the bug should
not rely on false code. btw., the mips- and the sun-compiler produces the
expected result - ok, i have to admit, that this also can be a bug of the
other compiler, so if you find out, that this is not correct c++-code,
please tell me.
error-message:
g++-bug.C: In instantiation of `C<int>::CB':
g++-bug.C:59: instantiated from here
g++-bug.C:41: Internal compiler error.
g++-bug.C:41: Please submit a full bug report.
g++-bug.C:41: See <URL:http://www.gnu.org/software/gcc/faq.html#bugreport>
for instructions.
error-description:
i included a test-program which contains three template classes.
class A is a base class, containing two member classes, one regular member
class and one template member class.
the second class B is just a regular class, which takes as second template
argument a member class of A.
class C contains two regular member classes, both derived from class B.
one with class A::AA as second template argument for B and one with
A::AB<int>.
the strange thing is, if class A has only one template parameter,
everything is ok. look also for the comments in bug-g++.C
i hope, i can help with this bug-report to improve g++.
gerd sussner
<sussner@informatik.uni-erlangen.de>
# 1 "g++-bug.C"
template<class T0,class T1>
class A {
public:
class AA {
};
template<class T2>
class AB : public AA {
};
};
template<class T0, class T3>
class B {
};
template<class T0>
class C {
public:
class CA : public B<T0,A<T0,int>::AA > { };
class CB : public B<T0,A<T0,int>::AB<int> > { };
};
main()
{
C<int>::CA a;
C<int>::CB b;
}
// This file causes gcc-2.95.2 to exit with an 'Internal compiler error'.
// The error occurs, if the first class below has more than one template
// arguments. If you define SHOW_BUG, the last line in main() causes gcc
// to exit. If you comment out the last line of main(), everything is ok.
// If you don't define SHOW_BUG, no error occurs in either case of the
// last line in main().
#define SHOW_BUG
// This is a class containing two member classes, one as regular class, the
// other as a template member class
#ifdef SHOW_BUG
template<class T0,class T1>
#else
template<class T0>
#endif
class A {
public:
class AA {
};
template<class T2>
class AB : public AA {
};
};
// Class B, which should use one of the member classes AA or AB of class A for
// the second template argument T3
template<class T0, class T3>
class B {
};
// Class C, which contains two member classes, both derived from class B. The
// difference is, that CB uses class AB as second template argument of
// class B.
template<class T0>
class C {
public:
#ifdef SHOW_BUG
class CA : public B<T0,A<T0,int>::AA > { };
class CB : public B<T0,A<T0,int>::AB<int> > { };
#else
class CA : public B<T0,A<T0>::AA > { };
class CB : public B<T0,A<T0>::AB<int> > { };
#endif
};
main()
{
// Here, class CA is used, i.e. derived from class B, with class AA as
// second template argument of class B
C<int>::CA a;
// INTERNAL COMPILER ERROR:
// Here, class CB is used, i.e. also derived from class B, but with
// class AB as template argument of class B. Remember, class AB
// is a template member class of class A, whereas class AA is a
// regular member class of class A.
C<int>::CB b;
}