Whilst I don't disagree that this is the case could you please cite the
part of the standard that codifies this? I cannot find anything in 3.8
of the 0x draft standard (which is all I have available).
It doesn't. This has been my interpretation of intent and
reasonableness of some very badly phrased sections in the standard.
Please see the comp.lang.c++.moderated thread.
In short, 3.8 Object Lifetime [basic.life] reads:
1 The lifetime of an object is a runtime property of the object. The
lifetime of an object of type T begins
when:
— storage with the proper alignment and size for type T is obtained,
and
— if T is a class type with a non-trivial constructor (12.1), the
constructor call has completed.
The lifetime of an object of type T ends when:
— if T is a class type with a non-trivial destructor (12.4), the
destructor call starts, or
— the storage which the object occupies is reused or released.
This is frankly bullshit. This means that any such storage has a near
limitless amount of objects co-existing in it. The only reasonable way
out seems to be to use the same fix of the union DR, which I've heard
is finally making it into the draft (maybe). (See that same comp.lang.c
++.moderated thread for some discussion. Someone there mentions a
recent thread on on comp.std.c++.)
3.8 Object Lifetime / 1 should read:
1 The lifetime of an object is a runtime property of the object. The
lifetime of an object of type T begins
when:
— storage with the proper alignment and size for type T is obtained,
and
— if T is a class type with a non-trivial constructor (12.1), the
constructor call has completed, /+ or if T is not a class type with a
non-trivial constructor, a write was made to the storage through a T
lvalue +/.
The lifetime of an object of type T ends when:
— if T is a class type with a non-trivial destructor (12.4), the
destructor call starts, or
— the storage which the object occupies is reused or released.
On the bright side, no one has corrected me yet, and I've gotten some
support, so I'm going to run with it. This appears to be the only
option which actually works on common implementations, such as gcc
without -fno-strict-aliasing, and it appears to be the solution
consistent with the proposed union DR fix. (I think / I hope. I'm
planning on reading that shortly.)