C++ Logo

SG12

Advanced search

Subject: Re: [ub] Implementation of assignment in std::optional and Core issue 1404: Object reallocation in unions
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2013-05-30 09:15:53


On 30 May 2013 16:57, Nikolay Ivchenkov <mk.ivchenkov_at_[hidden]> wrote:

>
> regardless of the definition of f (which may be unknown for compiler).
> There is no legal way to modify reference x.ref after its initialization
> so that it would refer to a different location. Even if we overwrite the
> storage of x by construction of a new object of type X at address &x (our f
> could do such thing), a compiler may assume that x.ref is untouched. The
> same applies to the original example with optional.
>
>
I see, thanks, that's a very good explanation. But there's still the
difference that the 3.8/7 would seem to refer to
the storage of A inside the optional (in the original example of yours),
and we never had a pointer or a reference
to that storage, but we have a reference inside that storage. Same with
this latest example of yours, isn't
explicit destruction and placement-new of x legal, and allowed to modify
the reference inside the storage
of x? If we had a pointer/reference to that storage previously, we wouldn't
be able to refer to the new
object via those, but in the example we do not have such a
pointer/reference.



SG12 list run by herb.sutter at gmail.com