[cxx-abi-dev] ::delete and deleting destructors

Dennis Handly dhandly at cup.hp.com
Thu Sep 6 04:27:56 UTC 2007


>From: Jason Merrill <jason at redhat.com>
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.

We would have to skip the class one and only use it for the "delete p" case.

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

aC++ also gets it wrong.
400025d0: ::op new(16)
40002630: ::op new(24)  <<<<
40002638: ctor base
40002640: ctor base2
40002630: ctor derived
40002630: dtor derived
40002640: dtor base2
40002638: dtor base
40002638: ::op delete  <<<<

>It seems to me that fixing this would require a change to the ABI, 
Jason

With Mark's suggestion, do we need to add that as an engineering note??

>From: Mark Mitchell <mark at codesourcery.com>
>Why can't the code generated by the compiler for "::delete x", where "x"
>is of type "X", a dynamic class, be:

>  // This is a virtual call, so calls the destructor for most-derived type.
>  x->X::~X();

By definition X::~X() isn't a virtual call but we need one??
It seems you can't write it in C++, without compiler help to access the
function pointer in the vtable.
(But this is a moot point since this doesn't change.)

>  // Call the global deallocation function
>  ::operator delete(p);
Mark Mitchell

That should do it.  And we have to do it in your order since vtbl pointer
gets changed by ~X.



More information about the cxx-abi-dev mailing list