[gclist] Finalization and death notices

Larry Evans jcampbell3@prodigy.net
Mon, 08 Oct 2001 19:04:09 -0500

Jerrold Leichter wrote:



> That's almost, but not quite, true.  The real problem is that delete *always*
> calls the destructor.  If the object has already been destructed, you're dead.
> You might think you could avoid this by having a flag set in your constructor
> and cleared in you destructor - but that gives you undefined behavior:  You
> aren't allowed to look at the object once it's been destructed.  Carrying the

I've experienced where the virtual function table is modified by the
DTOR; however, I'm not sure DTOR for POD will make access illegal.
  struct X{ int a;~X(){}}; X x; x.a=1;x.~X();cout<<x.a;
Is the last "look at" x.a in the output statement illegal?
Could you point out in the standard where this is specified?

> flag in memory owned by the allocator but outside the object doesn't work
> either - the destructor can't get at it, since it has no way to determine if
> it's being called on a heap- or stack-allocated object, hence no safe way to
> set the flag.