[cfe-dev] operator delete[] does not call derived class destructor

Florian Weimer fw at deneb.enyo.de
Sun May 20 22:25:12 PDT 2012

* M. E. O'Neill:

> In contrast, for arrays, what it needs to do is:
> - Call the destructors for all the objects in the array (starting at
>   the *end* of the array and working backwards)
> - call operator delete [] (void* ptr), where ptr start of the memory
>   block previously allocated with operator new[]
> It's the first of these things that is problematic.  How can the
> compiler know where that last element is.  It does know that the
> array has three things in it, but it can't use n*sizeof(Base) to
> calculate the value it needs, which is n*sizeof(Derived).

The element size could be written next to the place where the number
of elements is stored.  Or it could be derived from the vtable pointer
(which is the same for all the elements).  Probably not without ABI
changes, though.

More information about the cfe-dev mailing list