On Mon, Apr 25, 2016 at 9:57 PM, Jason Merrill <jason@redhat.com> wrote:
Hmm, this seems to assume that operator delete itself doesn't do
anything with the object being deleted. This is true of the default
implementation, but I don't see anything in the standard that
prohibits a user-supplied replacement or class-specific deallocation
function from accessing the memory.
Hmm, but the delete expression invokes the (default) destructor which
ends the lifetime of the object and thus invalidates all memory. Don't
we place a CLOBBER there as well nowadays (seems not).
For
struct A { A(); ~A(); int i; };
int main()
{
A *a = new A;
delete a;
}
I see
struct A * a;
<<cleanup_point <<< Unknown tree: expr_stmt
(void) (a = TARGET_EXPR <D.2346, operator new (4)>;, try
{
A::A ((struct A *) D.2346);
}
catch
{
operator delete (D.2346);
}, (struct A *) D.2346;) >>>>>;
<<cleanup_point <<< Unknown tree: expr_stmt
if (SAVE_EXPR <a> != 0B)
{
A::~A (SAVE_EXPR <a>);, operator delete ((void *) SAVE_EXPR <a>);;
}
else
{
<<< Unknown tree: void_cst >>>
} >>>>>;
so after the destructor is invoked the objects lifetime ends.