This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13115] 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 21:15:33 -0000
- Subject: [Bug c++/13115] New: wrong class hierarchy
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
using g++ version 3.2.2 and 3.3, for the following testcase:
struct A { };
struct B : public virtual A {
virtual double f();
};
struct C : public A { };
struct D : public A {
virtual double f();
};
struct E: public B, virtual public C { };
struct F: virtual public D, public virtual C {
int fi;
};
struct G : public E, public F, public virtual C { };
double B::f(){return 0.0;}
double D::f(){return 0.0;}
int main(void) {
G g;
return 0;
}
using g++ -fdump-class-hierarchy t.C command, we got the following class layout
for class G:
Class G
size=20 align=4
G (0x4009ad40) 0
vptridx=0 vptr=((&G::_ZTV1G) + 20)
E (0x4009ad80) 0 nearly-empty
primary-for G (0x4009ad40)
subvttidx=4
B (0x4009ae40) 0 nearly-empty
primary-for E (0x4009ad80)
subvttidx=8
A (0x4009ae80) 0 empty virtual canonical
vbaseoffset=-12
C (0x4009adc0) 16 empty virtual canonical
vbaseoffset=-16
A (0x4009ae00) 16 empty
F (0x4009aec0) 4
subvttidx=12 vptridx=20 vptr=((&G::_ZTV1G) + 44)
D (0x4009af80) 4 nearly-empty virtual canonical
primary-for F (0x4009aec0)
vptridx=24 vbaseoffset=-20
A (0x4009afc0) 4 empty
C (0x4009af00) 16 empty virtual non-canonical
A (0x4009af40) 16 empty
C (0x400a4000) 16 empty virtual non-canonical
vbaseoffset=-16
A (0x400a4040) 16 empty
This is wrong, because F and D are at offset 4, then at offset 8 should be F's
data member fi, then there is 4 bytes unused space, and then C is put at offset
16.
With g++ -fabi-version=2 -fdump-class-hierarchy t.C command, we got a different
class layout for G:
Class G
size=16 align=4
G (0x4817c0) 0
vptridx=0 vptr=((&G::_ZTV1G) + 20)
E (0x481800) 0 nearly-empty
primary-for G (0x4817c0)
subvttidx=4
B (0x4818c0) 0 nearly-empty
primary-for E (0x481800)
subvttidx=8
A (0x481900) 0 empty virtual canonical
vbaseoffset=-12
C (0x481840) 12 empty virtual canonical
vbaseoffset=-16
A (0x481880) 16 empty
F (0x481940) 4
subvttidx=12 vptridx=20 vptr=((&G::_ZTV1G) + 44)
D (0x481a00) 4 nearly-empty virtual canonical
primary-for F (0x481940)
vptridx=24 vbaseoffset=-20
A (0x481a40) 4 empty
C (0x481980) 12 empty virtual non-canonical
A (0x4819c0) 12 empty
C (0x481a80) 12 empty virtual non-canonical
vbaseoffset=-16
A (0x481ac0) 12 empty
This time, C is put at offset 12, but G's E's C's A object is put at offset 16,
and G's F's C's A is put at offset 12, so is G's C's A is also at offset12.
This is wrong, since these A should be the same A object.
--
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
GCC host triplet: linuxppc
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13115