[ub] [c++std-core-23844] Re: unions and undefined behavior

Lawrence Crowl Lawrence at Crowl.org
Wed Jul 24 20:59:09 CEST 2013


On 7/24/13, Jeffrey Yasskin <jyasskin at google.com> wrote:
> There's always the hack of destroying and re-constructing a node when
> you want to re-use its memory without going through the global
> allocator. Then you have to figure out what you need to do with
> pointers to keep them valid. e.g. is "p->~T(); new(p) T(...); use(p);"
> valid, or must one write "p->~T(); p = new(p) T(...); use(p);"? (note
> the extra "p=") [basic.life]p7 addresses this ... and says that for
> class types with a const-qualified data member, you do need to
> re-assign the pointer. (C++03 through C++14)

Note that the addition of non-trival members to unions specifically says
one should use this approach to change the active field.

-- 
Lawrence Crowl


More information about the ub mailing list