C++ Logo

sg12

Advanced search

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

From: Lawrence Crowl <Lawrence_at_[hidden]>
Date: Wed, 24 Jul 2013 11:59:09 -0700
On 7/24/13, Jeffrey Yasskin <jyasskin_at_[hidden]> 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

Received on 2013-07-24 20:59:10