When casting a const reference of a derived class (which inherits from multiple classes with virtual methods) to a non-const reference of one of it's base classes, the resulting non-const base class reference points to an incorrect address.
system type/gcc build options/version: Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/u sr/share/info --enable-shared --enable-threads=posix --enable-checking=release - -with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --with-gx x-include-dir=/usr/include/c++/3.4.3 --enable-libgcj-multifile --enable-language s=c,c++,java,f95 --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/ jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux Thread model: posix gcc version 4.1.0 20060515 (Red Hat 4.1.0-18) command line: compile code with command /usr/bin/g++4 cast.cpp execute a.out compiler output: no compiler messages execution of program results in "Segmentation fault" preprocessed file: # 1 "cast.cpp" # 1 "/home/hagin//" # 1 "<built-in>" # 1 "<command line>" # 1 "cast.cpp" class Shape { public: Shape() {} virtual ~Shape() {} }; class Loop { public: Loop() {} virtual ~Loop() {} virtual void func() {} }; class Rect : public Shape, public Loop { public: Rect() {} virtual ~Rect() {} }; int main () { const Rect* rect = new Rect(); ((Loop&)(*rect)).func(); return 0; } -- Summary: Reference casting involving multiple inheritance produces bad pointer Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hagin at us dot ibm dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31074