This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13114] New: wrong class hierarchy
- From: "yanliu at ca dot ibm dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Nov 2003 20:36:10 -0000
- Subject: [Bug c++/13114] New: wrong class hierarchy
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The testcase failed on both g++ 3.3 and 3.2.2 versions on linuxppc machine.
Here is the testcase:
struct W { };
struct X : public W { };
struct Y : public W { };
struct Z : virtual public X, public Y { };
struct ZZ : public Z {
int i;
int func() { return 0;};
};
int main(void) {
ZZ zz;
return 0;
}
using g++ -fdump_class_hierarchy t.C with/without option -fabi-version=2 ( what
this option means? I could not find this "2" meaning in option description.)
we got two different class hierarchy. But both are incorrect. Here is the class
layout of ZZ without -fabi-version=2 option ( the default should be -fabi-
version=0):
Class ZZ
size=8 align=4
ZZ (0x40983b00) 0
vptridx=0 vptr=((&ZZ::_ZTV2ZZ) + 12)
Z (0x40983b40) 0 nearly-empty
primary-for ZZ (0x40983b00)
subvttidx=4
X (0x40983c00) 4 empty virtual canonical
vbaseoffset=-12
W (0x40983c40) 4 empty
Y (0x40983b80) 0 empty
W (0x40983bc0) 0 empty
This class hierarchy is wrong, because the base class X shares the same offset
with ZZ's data member int i.
Using g++ -fabi-version=2 -fdump-class-hierarchy t.C, I got a different class
layout for ZZ:
Class ZZ
size=12 align=4
ZZ (0x40983b00) 0
vptridx=0 vptr=((&ZZ::_ZTV2ZZ) + 12)
Z (0x40983b40) 0 nearly-empty
primary-for ZZ (0x40983b00)
subvttidx=4
X (0x40983c00) 8 empty virtual canonical
vbaseoffset=-12
W (0x40983c40) 12 empty
Y (0x40983b80) 0 empty
W (0x40983bc0) 0 empty
This time the offset of X's W is at offset 12, which is also wrong according to
C++ ABI, it should be put at the same offset with X.
--
Summary: wrong class hierarchy
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: yanliu at ca dot ibm dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13114