::delete and deleting destructors

Jason Merrill jason at redhat.com
Wed Sep 5 16:21:18 UTC 2007


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15097

seems to indicate a problem with the ABI.  The standard requires that 
::delete use the global operator delete, but properly deleting an object 
of a type with a virtual destructor requires that use the deleting 
destructor, which will call the operator delete declared in the class, 
if any.

G++ gets this wrong by always calling the global operator delete, which 
means freeing the wrong pointer in the presence of multiple inheritance.

ICC tries to split the difference by using the deleting destructor if 
the static type doesn't have a user-declared op delete, so they free the 
wrong pointer if the static type of the object has a user-declared op 
delete, and call the wrong op delete if the static type doesn't but the 
dynamic type does.

It seems to me that fixing this would require a change to the ABI, 
either to return the address to be deleted from the non-deleting 
destructor, add an additional deleting destructor, or add a hidden 
parameter to the existing deleting destructor.  The last could probably 
be implemented as a backwards-compatible change.

Jason



More information about the cxx-abi-dev mailing list