Boost logo

Boost :

Subject: Re: [boost] aligned_storage in unions
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-09-22 15:05:55


On 09/22/10 13:46, Mathias Gaunard wrote:
> On 22/09/2010 18:35, Larry Evans wrote:
>> How would C++0x avoid the problem?
>
> By allowing to put non-PODs in unions.
>
>
>> Could you point to the variant code violating this rule?
>
> aligned_storage<whatever>::type is a POD type of a certain type T.
> In order to read and write any of the object a variant can hold, it will
> need to reinterpret cast from a pointer to that object to a pointer to
> any of these object types, that are not necessarily the same as T.

I thought variant just static_cast<char*> to void* then from void* to
T*. The char* is for the memory buffer in boost::aligned_storage.
IOW, it doesn't use reinterpret_cast. To confirm, I did:

  find . -name \*.hpp -exec grep _cast {} \; -ls

in boost/variant and only found static_cast.

Now, as far as Frank's point about operator=, my reply to his
post indicated there would never be a case where two pointers
of different types and pointing to the same memory location
would be in scope at the same time in the operator= implementation,
at least for the container_one_of_maybe mentioned in my reply.
I don't know if that is true for boost::variant.

-Larry


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk