[gclist] Finalization and death notices

Tim Hollebeek thollebeek@cigital.com
Mon, 8 Oct 2001 21:30:17 -0400


> Consider:
>   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?
> TIA

>From the Dec 1996 WP (sorry, don't have anything more recent handy)
AFAIR this sort of thing didn't change.

class.dtor.14: 
"Once a destructor is invoked for an object, the object no longer
exists; ..."

which in C++ standardese implies that x.a=1 invokes undefined behavior.

class.dtor.14 then continues with an example:

[Example:  if  the destructor  for  an  automatic  object  is explicitly
invoked, and the block is subsequently left in a manner that  would
ordinarily  invoke implicit destruction of the object, the behavior is 
undefined.  ]

So your snippet is doubly-undefined (i.e. it invokes undefined behavior
even *without* the access to x.a)

Tim Hollebeek
Research Scientist
Cigital Labs, Inc.