Leigh Johnston wrote:
[...]
It is possible to re-seat a member reference in a user provided
assignment
operator by doing something similar to the following:
const foo& foo::operator=( const foo& other)
{
if ( this != &other )
{
this->~foo(); // lifetime of *this ends
new (this) foo(other); // new object of type foo created
}
return *this;
}
Actually, I re-read [3.8/7]; and now I find that the above is not
solving
the problem of reseating references. [3.8/7] states:
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 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 operational words are "or a reference type".
BTW: this is also in n3035.
Best
Kai-Uwe Bux
Ah well spotted I failed again, damn UB. :)