C++ virtual function crash with gcc-2.95.1

Andrew S. Townley atownley@informix.com
Fri Nov 19 07:47:00 GMT 1999


Hello,

I encountered this behavior when attempting to verify a new bundle of a
project with gcc-2.95.1 on Solaris.  The same code will compile on
gcc-2.8.1 under Solaris and egcs-1.1.2 on Linux.  The test case distills
the problem down to a simple case that I hadn't noticed before.  The
issue seems to be that gcc gets confused when instantiating the derived
template class because the base class's pure virtual method actually has
an implementation defined.

I have corrected my code, but I thought you might like to know that the
way gcc handles this case isn't too graceful :)

Thanks in advance,

ast

Here's the compiler output:

cyclone> gcc -v --save-temps bug.cpp
Reading specs from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/specs
gcc version 2.95.1 19990816 (release)
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/cpp -lang-c++ -v
-D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dsparc
-Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__
-D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix)
-Asystem(svr4) -D__EXCEPTIONS -D__GCC_NEW_VARARGS__ -Acpu(sparc)
-Amachine(sparc) bug.cpp bug.ii
GNU CPP version 2.95.1 19990816 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:

/usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/../../../../include/g++-3
 /usr/local/include

/usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/../../../../sparc-sun-solaris2.6/include
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/include
 /usr/include
End of search list.
The following default directories have been omitted from the search
path:
End of omitted list.
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/cc1plus bug.ii
-quiet -dumpbase bug.cc -version -o bug.s
GNU C++ version 2.95.1 19990816 (release) (sparc-sun-solaris2.6)
compiled by GNU C version 2.95.1 19990816 (release).
bug.cpp: In instantiation of `A<char>::op()':
bug.cpp:30:   instantiated from here
bug.cpp:11: Internal compiler error.
bug.cpp:11: Please submit a full bug report.
bug.cpp:11: See <URL: http://www.gnu.org/software/gcc/faq.html#bugreport >
for instructions.

Here's the source file:

cyclone> cat bug.ii
# 1 "bug.cpp"
template<class T>
class A
{
public:
	A() {};
	virtual void op() = 0;
};

template<class T>
void A<T>::op()
{
}

template<class T>
class B : public A<T>
{
public:
	virtual void op();
};

template<class T>
void B<T>::op()
{
}

main()
{
	B<char>	b;
}


More information about the Gcc-bugs mailing list