c++/8390: Object layout: empty virtual base allocation failure
grigory@stl.sarov.ru
grigory@stl.sarov.ru
Tue Oct 29 00:10:00 GMT 2002
>Number: 8390
>Category: c++
>Synopsis: Object layout: empty virtual base allocation failure
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Oct 28 23:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Grigory Zagorodnev
>Release: 3.2
>Organization:
>Environment:
$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
>Description:
In the test-case listed below, G++ 3.2 compiler makes wrong layout of class C4. Empty virtual base C3 takes non-empty space.
--- fail.cpp ------------------------
struct C3
{
};
struct C2: C3
{
virtual int f1() { return 2; }
};
struct C4: C2, virtual C3
{
short m1;
C4() { m1 = (short) 0x4444; }
};
C4 obj;
-------------------------------------
Object layout (got from "g++ -fdump-class-hierarchy -c fail.cpp") is:
Class C4
size=12 align=4
C4 (0x4031cc00) 0
vptridx=0 vptr=((&C4::_ZTV2C4) + 12)
C2 (0x4031cc40) 0 nearly-empty
primary-for C4 (0x4031cc00)
C3 (0x4031cc80) 0 empty
C3 (0x4031ccc0) 8 empty virtual canonical
vbaseoffset=-12
The binary dump of object is:
[obj+0x00] Virtual table _ZTV2C4, adress point 0xc
[obj+0x04] 00004444
[obj+0x08] 00000000
We see that virtual base C3 is allocated at offset 8 and takes 4 bytes. There is the misstake - C3 should not take any space here!
Expected layout is (binary format):
[obj+0x00] Virtual table _ZTV2C4, adress point 0xc
[obj+0x04] 00004444
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list