http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48035
Summary: Mismatch on size of class when initializing hierarchy involving virtual inheritance and empty base classes Product: gcc Version: 4.4.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: scot4s...@yahoo.com Created attachment 23585 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23585 preprocessed source file The attached preprocessed source file is a much-simplified version of a more complex class hierarchy involving several levels of virtual inheritance and empty classes in the hierarchy. "g++ -v" details: Using built-in specs. Target: i686-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch=i686 --build=i686-redhat-linux Thread model: posix gcc version 4.4.5 20101112 (Red Hat 4.4.5-2) (GCC) Also tested with a new build: Using built-in specs. COLLECT_GCC=./g++ Target: i686-pc-linux-gnu Configured with: ./configure Thread model: posix gcc version 4.5.2 (GCC) Among others. Compile with "g++ -c vtable-bug.i". What we observe (tested on x86 and ARM) is that "operator new" is called to allocate 12 bytes for the class (and sizeof matches that 12 byte size), but the compiled code then proceeds to load four-byte 0's into offsets 0, 4, 8, AND 12 from the allocated buffer, stomping data at byte offsets 12-15. (More complex hierarchies can result in more than one 4-byte offset being stomped, and/or the same offset being initialized repeatedly.) Changing which classes are virtual, or adding data to empty base classes, changes or fixes the behavior.