BUG report for egcs 1.1a - RTTI segfault

Andreas Scherer andreas.scherer@pobox.com
Mon Sep 14 00:05:00 GMT 1998


Hello all,

I am sure you will have received similar reports concerning the
following infelicity of egcs version 1.1a, and possibly there might be
even some notes about it somewhere in the documentation, but anyhow I
shall repeat my findings with all details that may be of help to you in
order to fix it in one of the next versions of the compiler.

In the following I am talking about

   gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

on a Linux system 2.0.33 (S.u.S.E. Linux 5.2) running on Intel Pentium
133. The compiler was installed by "./configure
--host=i586-pc-linux-gnulibc1", "make", and "make install" with no
further ado. Identical results can be obtained on Sun Sparc running
SunOS 4.1.2 with "./configure" (automatic system detection), "make", and
"make install".

Compiling the C++ source code

< Cut here ... >
#include <iostream>
#include <typeinfo>

class A
{
public:
   A( void ) {}
   virtual ~A( void ) {}
};

class B : public A
{
public:
   B( void ) {}
   virtual ~B( void ) {}
};

int main( void )
{
   A* pa = new B;
   B* pb = dynamic_cast< B* >( pa );

   cout << "pa points " << ( pb ? "" : "not " ) << "to an A." << endl;

   A* ppa = new A;
   B* ppb = dynamic_cast< B* >( ppa );

   cout << "ppa points " << ( ppb ? "" : "not " ) << "to an A." << endl;

   try
   {
      B& rb = dynamic_cast< B& >( *pa );
   }
   catch( bad_cast )
   {
      cout << "Oops, *pa was not a B!" << endl;
   }

   cout << "*pa is a B." << endl;

   try
   {
      B& rrb = dynamic_cast< B& >( *ppa );
   }
   catch( bad_cast )
   {
      cout << "Oops, *ppa was not a B!" << endl;
   }
}
< ... and here >

with the command "g++ -o rtti rtti.cxx -Wall" produces absolutely no
warnings and results in an ELF executable "rtti" that prints the output

< Cut here ... >
pa points to an A.
ppa points not to an A.
*pa is a B.
Segmentation fault
< ... and here >

According to any recent book on C++ one should expect the output line
"Oops, *ppa was not a B!" instead of the nasty "Segmentation fault", in
order to continue from the second "catch( bad_cast )" handler. Even
with   rather old compiler such as Microsoft Visual C++ 4.1 on Windows
NT 4.0 it is possible to use a construct as displayed in the final
section of the example code above, and I really would like to see egcs
follow suite in this respect.

Should you need further details to work on this problem, feel free to
get in contact with me via e-mail.

Best regards,

-- Andreas Scherer

PS: egcs version 1.1a was installed on September 11 instead of version
1.1b, because the archive egcs-1.1b.tar.gz on ftp://ftp.uni-berlin.de
(Germany) could not be unpacked correctly (gzip and winpkzip both
failed).

PPS: Thanks for the "namespace" feature! This is far better than the
message issued by egcs version 1.0.2. ;-)

PPPS: Currently I am testing egcs 1.1a on example applications that use
more conventional features of the C++ language, and even heavy use of
STL stuff results in programs that run perfectly (as they already did
with version 1.0.2).



More information about the Gcc-bugs mailing list