Boost logo

Boost :

Subject: [boost] [spirit] hold_any invalid assignment to destructed object?
From: Rob Desbois (rob.desbois_at_[hidden])
Date: 2013-03-11 12:51:02


Hi,

The boost::spirit::hold_any implementation includes the following functions
defined in the detail sub-namespace:

    // member of fxns<mpl::true_> specialisation, line 99
    static void move(void* const* src, void** dest)
    {
        reinterpret_cast<T*>(dest)->~T();
        *reinterpret_cast<T*>(dest) =
            *reinterpret_cast<T const*>(src);
    }

    // member of fxns<mpl::false_> specialisation, line 99
    static void move(void* const* src, void** dest)
    {
        (*reinterpret_cast<T**>(dest))->~T();
        **reinterpret_cast<T**>(dest) =
            **reinterpret_cast<T* const*>(src);
    }

As I understand it, the object is destroyed _and then assigned to_; does it
not need to be constructed at this point, i.e. have something like this
(for the first specialisation):

        new (reinterpret_cast<T*>(dest)) T(
            *reinterpret_cast<T const*>(src) );

Thanks & apologies if I've misunderstood
--rob
<http://theotherbranch.wordpress.com/>


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