[cxx-abi-dev] When to emit deleting destructor
scott douglass
sdouglass at arm.com
Wed Oct 16 15:28:51 UTC 2002
Mark Mitchell wrote:
>> [3] Change deleting destructors for non-virtual destructors to be
>> optional and caller-produced (in it own COMDAT group) like the allocating
>> constructors (C3).
>
>
> The ways you can make use of such a thing are very limited. (I think
> you know this, but just so that everyone understands the implications...)
>
> If you ever emit a call to the optional deleting destructor, you are
> depending on the deleting destructor being around, which you can't be
> sure will happen if some other compiler compiles the destructor.
I meant for non-virtual deleting destructors (D0) to be produced by the caller like allocating constructors (C3) are.
> So,
> this works only when the destructor definition is visible to you at the
> time that you are processing the delete expression.
If the caller can't see the body of the destructor it can produce a deleting destrcutor (D0) that uses the complete object destructor (D1). Aside: If the body of the destructor is present then the complete object destructor (D1) can be inlined into the deleting destrcutor (D0).
> [...]
> So, the only benefit to your proposal is that by giving a standard name
> to the destructor, there is a way for callers to collapse those
> functions across translation units.
Yes. The same applies to allocating constructors (C3), right?
>>> This is a good question; it is unspecified at present.
>>>
>>> G++'s D0 destructors do not handle a NULL this pointer.
>>>
>>> What do HP and Intel do?
>>
>
> Yes; we never heard from HP and Intel. HP, Intel?
After some rummaging 'round my mailboxes I found that Dennis Hardy wrote:
> In aC++, all three destructors check for NULL "this" pointers.
>> I think the best resolution is that deleting destructors for virtual
>> destructors may assume this != 0 and deleting destructors for non-virtual
>> destructors must handle this == 0.
>
>
> Why do you think that is best? (I don't mean to be argumentative; I'm
> just curious why you came to this conclusion.)
My reasoning went like this:
Deleting destructors are only invoked for delete expressions, e.g.
delete p;
for non-virtual destructors:
More code (the null test) can be shared when the deleting destructor (D0) is not inlined
A compiler that wants to optimize away the call in the null case still can (although the
test in the deleting destructor becomes useless).
for virtual destructors:
you can't do the virtual dispatch to the deleting destructor on a null pointer so
you have to do the test at the delete site anyway.
More information about the cxx-abi-dev
mailing list