
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 28 April 2008 09:27 am, Peter Dimov wrote:
Daniel Frey:
Consider:
class Object { static map< string, shared_ptr< Object > > cache;
Object() { cache.insert( make_pair( "foo", shared_from_this() ) ); throw 42; } };
With the above BOOST_ASSERT(_shared_count.empty()), ::abort() seems to most sensible thing we can do, otherwise it would lead to very dangerous situations where cache contains a shared_ptr to a deleted object.
The original assert catches this case, does it not?
Yes. The difference would be if cache was: static map< string, weak_ptr< Object > > cache; Then the current assert would allow it (and it would probably be safe at least in a single-threaded context), but BOOST_ASSERT(_shared_count.empty()) would abort. - -- Frank -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIFfdY5vihyNWuA4URAvhbAJ9MzZO+arh/mrbr6i0KCRXF6QM4zQCfS/EA 1rReoupBhiB/cStdvJQJeU8= =RWWF -----END PGP SIGNATURE-----