Assuming the reinterpret_cast
s are well-defined (that is, dest
really is a pointer to pointer to T
), the standard defines the end of an object's lifetime as:
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.
It then gives some restrictions over what can be done with the glvalue **reinterpret_cast<T**>(dest)
:
Similarly, [...] after the lifetime of an object has ended and before the storage which the object occupied is reused or released, any glvalue that refers to the original object may be used but only in limited ways. [...] The program has undefined behavior if:
- an lvalue-to-rvalue conversion (4.1) is applied to such a glvalue,
- the glvalue is used to access a non-static data member or call a non-static member function of the object, or
- the glvalue is implicitly converted (4.10) to a reference to a base class type, or
- the glvalue is used as the operand of a static_cast (5.2.9) except when the conversion is ultimately to cv char& or cv unsigned char&, or
- the glvalue is used as the operand of a dynamic_cast (5.2.7) or as the operand of typeid.
Emphasis added.
If the object doesn't end up in this after-life state because it has a trivial destructor, there is no problem. However, for any T
which is a class type with non-trivial destructor, we know that the assignment operator is considered a member function operator=
of that class. Calling a non-static member function of the object through this glvalue results in undefined behaviour.