[cxx-abi-dev] When to emit deleting destructor

scott douglass sdouglass at arm.com
Wed Oct 16 08:23:31 UTC 2002


Mark Mitchell wrote:
> The current ABI document says:
> 
>   That is, user-defined constructors or destructors, unless the
>   function is declared inline, or has internal linkage, are emitted
>   where defined, with their complete, and base object variants. For
>   destructors, the deleting variant is emitted as well.
> 
> The reason is that in the C++ standard, we have:
> 
>   [class.dtor]
> 
>   At the point of definition of a virtual destructor (including an
>   implicit definition (_class.copy_)), non-placement operator delete
>   shall be looked up in the scope of the destructor's class
>   (_basic.lookup.unqual_) and if found shall be accessible and
>   unambiguous.
> 
> There's no guarantee that operator delete will be unambiguous in a
> non-virtual destructor, and it therefore doesn't make sense to
> generate a deleting destructor in that case.
> 
> If I do not hear objections over the next couple of days, I will
> modify the sentence above to read:
> 
>   For virtual destruct[ors], the deleting variant is emitted as well.
> 
> (FWIW, G++ already omits the delting destructor if the destructor is
> non-virtual.)

If I understand correctly it would mean that classes with non-virtual destructors no longer have any deleting destructor (D0).  I think these are the obvious options:

  [0] No change.
    Not really implementable for classes with a non-virtual destructor and an ambiguous operator delete.

  [1] Drop deleting destructors entirely for non-virtual destructors.
    Mark's suggestion above.

  [2] Drop deleting destructors entirely for non-virtual destructor if the operator delete is ambiguous.

  [3] Change deleting destructors for non-virtual destructors to be optional and caller-produced (in it own COMDAT group) like the allocating constructors (C3).

Personally, I like option [3] best.

Additionally I'd like to resolve this question:

>> I have a question about delet[ing] destructors (D0).  Must they handle being
>> passed a null this pointer?
> 
> 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?

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.




More information about the cxx-abi-dev mailing list