[smart_ptr] regression test case enhancement

I wrote two reference implementations for enable_shared_from_this.hpp, both are now in <https://svn.boost.org/svn/boost/sandbox/libs/smart_ptr/daniel_frey>. Both are tested and pass all regression tests - except for the non-enhanced version which obviously doesn't pass esft_constructor_test. The important thing is, that this test showed something else: The current tests without esft_constructor tests don't check who takes ownership of an enable_shared_from_this-derived object in case there are multiple simultaneous owners available. The attached patch checks that - and AFAICT it would fail with the 1.35.0 esft. (Both reference versions from above do pass). Should this be added? Regards, Daniel

Daniel Frey:
The important thing is, that this test showed something else: The current tests without esft_constructor tests don't check who takes ownership of an enable_shared_from_this-derived object in case there are multiple simultaneous owners available.
The attached patch checks that - and AFAICT it would fail with the 1.35.0 esft. (Both reference versions from above do pass).
Should this be added?
We first need to decide which one we want to test for. The new behavior looks slightly better to me; when two shared_ptr instances take ownership of the same object, it's likely that the first one is the "legitimate" owner and the second one uses a null deleter.

On Wed, 2008-04-30 at 20:34 +0300, Peter Dimov wrote:
We first need to decide which one we want to test for. The new behavior looks slightly better to me; when two shared_ptr instances take ownership of the same object, it's likely that the first one is the "legitimate" owner and the second one uses a null deleter.
I also prefer that an update of the internal _weak_ptr only happens when the object is currently not owned. Otherwise, I think we might also run into scoping problems like this: struct X : enable_shared_from_this<X> {}; shared_ptr<X> x1( new X() ); x1->shared_from_this(); // OK { shared_ptr<X> x2( x1.get(), null_deleter() ); x2->shared_from_this(); // OK } x1->shared_from_this(); // throws bad_weak_ptr... Regards, Daniel
participants (2)
-
Daniel Frey
-
Peter Dimov