Boost logo

Boost :

Subject: Re: [boost] [interest] underlying type library
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-08-21 05:36:48


On 20.08.2011, at 19:45, Olaf van der Spek wrote:

> On Sat, Aug 20, 2011 at 6:28 PM, Mathias Gaunard
> <mathias.gaunard_at_[hidden]> wrote:
>> You cannot use bitwise copy to implement move semantics.
>> That just doesn't work.
>
> Hmm, why not? What breaks if you do a bitwise swap?

To begin with, the standard. It disallows this kind of thing, period. No matter that "it works in practice" or anything like that, it's undefined behavior to memcpy over a non-pod type's bytes. I think it's a bad idea to offer an easy way to do this in a Boost library.

I imagine, for example, that some implementations of virtual inheritance (that don't store offsets to the vbases in the vtable, but instead store a pointer directly in the object) would yield very interesting results.

Also, a slicing swap using this technique would be even more disastrous than usual for anything with a vtable.

Concerning internal pointers, something that would be high at risk would be a std::string with SBO that stores the end pointer.

Sebastian


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