[patch] Fix std::experimental::any for small, non-trivial objects

Jonathan Wakely jwakely@redhat.com
Sat May 2 13:04:00 GMT 2015


On 02/05/15 13:39 +0100, Jonathan Wakely wrote:
>My initial implementation of experimental::any was too dumb, it
>assumed you could just swap the bytes of _Storage, and return it from
>functions like any POD type, but if the _Storage object contains a
>non-trivially-copyable object internally (not on the heap) then it's
>wrong to treat it as a POD.
>
>This patch makes the _Storage object non-copyable and fixes all the
>uses of it.
>
>Tested powerpc64le-linux, committed to trunk.

Here's a much smaller patch for the gcc5 branch, which just avoids the
small-object optimisation for non-trivially-copyable types. This
pessimises some types, but is safe.

(Given that this stuff is all "experimental" anyway, maybe we could
just backport the full fix from trunk, but this is OK for now.)

Tested powerpc64le-linux, committed to gcc-5-branch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 2998 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20150502/2d456851/attachment.bin>


More information about the Libstdc++ mailing list