[cfe-dev] Microsoft vtordisp field support for clang.
John McCall
rjmccall at apple.com
Wed Feb 15 10:13:42 PST 2012
On Feb 15, 2012, at 12:12 AM, r4start wrote:
> 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.
Okay. I was just noticing that 'C' installs a construction v-table for A, and
that v-table has to include a thunk for foo() that's really in exactly the
same situation as a thunk would be if B inherited from A virtually. I guess
Microsoft just gave up in this case.
John.
More information about the cfe-dev
mailing list