Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2008-04-29 02:18:16


I think there are cases not caught by the current assert condition:

struct A : boost::enable_shared_from_this<A> {};

int main()
{
  boost::shared_ptr<A> pa;
  {
    A a;
    pa = a.shared_from_this();
    boost::shared_ptr<A> pa2( &a );
    // here, first 'pa2' and then 'a' goes out of scope!
  }
  // now 'pa' still exists and points to a deleted object
}

What do you think of the following condition:

BOOST_ASSERT( _weak_count.use_count() == 0 ||
              _shared_count.use_count() == 1 );

It passes all regression tests and catches the above case. Do you see
any problem with it or shall I commit it?

Regards, Daniel


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