question on the virtual base offset
Yan Liu
yanliu at ca.ibm.com
Tue Aug 31 22:14:36 UTC 2004
I found that g++ 3.3, 3.4 and 3.5 have different class layout for the
following testcase:
struct A {char a;};
struct B: virtual public A {};
struct C:public B{
int c;
virtual void f() {};
};
struct D {
char d;
};
struct E {int:3;};
struct F: public C, virtual E, public D {
char f1;
virtual void f(){}
};
int main()
{F f;}
Attached files are the class and vft layout results with three g++
compilers using -fdump-class-hierarchy option.
(See attached file: temp4.g++35.class)(See attached file:
temp4.g++33.class)(See attached file: temp4.C.g++34_32.class)
According to the C++ ABI online document chapter 2.4
(http://www.codesourcery.com/cxx-abi/abi.html). After mapping the virtual
base class A while mapping of the most derived class F, the dsize(F)=11,
size(F)=11, align(F)=4, and nvsize(E)=4, nvalign(E)=4. So, when mapping
virtual base class E, the next available bits are at offset dsize(F)=11. E
should be put at offset(F) which is the dsize(F) =11, and the final class
size should be 12. To me, g++3.4 gives the most reasonable result, I don't
understand why g++3.5 put E at offset 12, and the final class size is 16.
Is it means that ABI has changed or just a gcc bug?
Your kind help is highly appreciated. Thanks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: temp4.g++35.class
Type: application/octet-stream
Size: 2200 bytes
Desc: not available
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20040831/2a42679a/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: temp4.g++33.class
Type: application/octet-stream
Size: 1744 bytes
Desc: not available
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20040831/2a42679a/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: temp4.C.g++34_32.class
Type: application/octet-stream
Size: 2200 bytes
Desc: not available
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20040831/2a42679a/attachment-0002.obj>
More information about the cxx-abi-dev
mailing list