[cfe-dev] Microsoft vtordisp field support for clang.
r4start
r4start at gmail.com
Wed Feb 15 00:12:57 PST 2012
On 15/02/2012 05:52, John McCall wrote:
> On Feb 14, 2012, at 3:40 AM, r4start wrote:
>> On 14/02/2012 15:34, r4start wrote:
>>> On 14/02/2012 05:06, John McCall wrote:
>>>> class A { virtual void foo(); } class B : public A { }; class C : public virtual B { C(); virtual void foo(); };
>>> For this test we will get next result:
>>> class C size(12):
>>> +---
>>> 0 | {vbptr}
>>> +---
>>> 4 | (vtordisp for vbase B)
>>> +--- (virtual base B)
>>> | +--- (base class A)
>>> 8 | | {vfptr}
>>> | +---
>>> +---
>>> If somewhere in inheritance path class has declare ctor or dtor and overload virtual method from virtual base,
>>> then before virtual base Microsoft compiler push vtordisp in layout.
>>>
>> Also for this test case:
>>
>> class A { virtual void foo(){} };
>> class B : public A { };
>> class C : public virtual B { C(){} virtual void foo(){} };
>> class D : public C { int qqq; };
>>
>> class D size(16):
>> +---
>> | +--- (base class C)
>> 0 | | {vbptr}
>> | +---
>> 4 | qqq
>> +---
>> 8 | (vtordisp for vbase B)
>> +--- (virtual base B)
>> | +--- (base class A)
>> 12 | | {vfptr}
>> | +---
>> +---
>> As you can see D also has vtordisp for B.
> Okay. I don't think this fundamentally changes the algorithm. I did think of
> a case that might matter, though: a superclass might override a method
> from a non-virtual base that is *also* a virtual base in some derived class.
> That is to say, is there a vtordisp in 'C' in the following code?
>
> class A { virtual void foo(); };
> class B: public A { virtual void foo(); B(); };
> class C : public B, public virtual A { C(); };
>
Class C does not have vtordisp, because C does not override 'foo' and B
inherit A non-virtual.
- Dmitry.
More information about the cfe-dev
mailing list