I think I found the answer in a passage below the "quoted" one that talks about trivial dtor / dtor side effects, namely [basic.life]/7:
If, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, a new object is created at the storage location which the original object occupied, a pointer that pointed to the original object, a reference that referred to the original object, or the name of the original object will automatically refer to the new object and, once the lifetime of the new object has started, can
be used to manipulate the new object, if:
the storage for the new object exactly overlays the storage location which the original object occupied, and
the new object is of the same type as the original object (ignoring the top-level cv-qualifiers), and
the type of the original object is not const-qualified, and, if a class type, does not contain any non-static data member whose type is const-qualified or a reference type, and
the original object was a most derived object of type T
and the new object is a most derived object of type T
(that is, they are not base class subobjects).
By reusing the storage, we end the lifetime of original object [basic.life]/1
The lifetime of an object of type T
ends when:
if T
is a class type with a non-trivial destructor, the destructor call starts, or
the storage which the object occupies is reused or released.
So I think [basic.life]/7 covers the situation
Reference<int> r(x);
new (&r) Reference<int>(y);
where we end the lifetime of the object denoted by r
, and create a new object at the same location.
As Reference<int>
is a class type with a reference data member, the requirements of [basic.life]/7 are not fulfilled. That is, r
might not even refer to the new object, and we may not use it to "manipulate" this newly created object (I interpret this "manipulate" also as read-only accesses).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…