On 21 May 2018 at 15:39, Steven Schveighoffer via Digitalmars-d
<digitalmars-d@puremagic.com> wrote:
> On 5/21/18 6:26 PM, Manu wrote:
>>
>> On 21 May 2018 at 14:53, Jonathan M Davis via Digitalmars-d
>> <digitalmars-d@puremagic.com> wrote:
>>>
>>> On Monday, May 21, 2018 14:33:44 Manu via Digitalmars-d wrote:
>>>>
>>>> How do virtual destructors work in normal D classes?
>>>
>>>
>>> It is my understanding that destructors in D are never virtual but rather
>>> that the runtime handles calling them correctly.
>>
>>
>> Can someone please elaborate on this?
>> I want to know exactly what this means in practise.
>>
>
> What he means by never virtual is *ALWAYS* virtual ;) At least in the sense
> of virtual C++ destructors, not ordinary virtual functions.
>
> Here is what the runtime does:
>
> https://github.com/dlang/druntime/blob/38d784a8acd9cfe6ff4dadac6883a40f392f7353/src/rt/lifetime.d#L1380
>
> In essence, each classinfo has it's "local" destructor,

Oooooohhh! It's in the classinfo (and not in the vtable!).
I knew that actually, I have run into that code, I just forgot!

Okay, so it's not directly in the vtable, it's special-case... (it's
actually an additional indirection over C++ to reach the dtor)
Proper extern(C++) handling will need to take that same function and
jam it in the first slot of the C++ vtable instead, but it should be
functionally identical I think.

Reply via email to