Boost logo

Boost :

Subject: Re: [boost] [shared_ptr] Ticket 2126 status?
From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-10-11 08:31:22


Andrey Semashev:

> Is the ticket 2126:
>
> http://svn.boost.org/trac/boost/ticket/2126
>
> actually fixed in trunk? The ticket is still open, but my code that uses
> enable_shared_from_this and make_shared runs fine on trunk.

Interesting. No, I don't believe that trunk is OK. The constructor support
just masks the problem. Try for example the following test:

#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/make_shared.hpp>
#include <boost/detail/lightweight_test.hpp>

struct X: boost::enable_shared_from_this<X>
{
    bool destroyed_;

    X(): destroyed_( false ) {}
    ~X() { destroyed_ = true; }
};

int main()
{
    boost::shared_ptr<X> px = boost::make_shared<X>();
    boost::shared_ptr<X> px2 = px->shared_from_this();

    BOOST_TEST( px == px2 );
    BOOST_TEST( !( px < px2 ) && !( px2 < px ) );

    px.reset();

    BOOST_TEST( !px2->destroyed_ );

    return boost::report_errors();
}


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