New enable_shared_from_this tests, fix.

[SVN r43829]
This commit is contained in:
Peter Dimov
2008-03-24 16:00:28 +00:00
parent d17a096407
commit af7d4fabad
2 changed files with 38 additions and 2 deletions

View File

@@ -95,7 +95,7 @@ public:
{
init_internal_shared_once();
get_deleter<detail::sp_deleter_wrapper>(_internal_shared_this)->set_deleter(owner);
owner = dynamic_pointer_cast<U>(_internal_shared_this);
owner.reset( _internal_shared_this, owner.get() );
_internal_shared_this.reset();
_owned = true;
}

View File

@@ -16,6 +16,7 @@
#include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <memory>
#include <string>
class X: public boost::enable_shared_from_this< X >
{
@@ -65,7 +66,7 @@ public:
int X::instances = 0;
int main()
void test()
{
BOOST_TEST( X::instances == 0 );
@@ -131,6 +132,41 @@ int main()
}
BOOST_TEST( X::instances == 0 );
}
struct V: public boost::enable_shared_from_this<V>
{
virtual ~V() {}
std::string m_;
};
struct V2
{
virtual ~V2() {}
std::string m2_;
};
struct W: V2, V
{
};
void test2()
{
boost::shared_ptr<W> p( new W );
}
void test3()
{
V * p = new W;
boost::shared_ptr<void> pv( p );
BOOST_TEST( pv.get() == p );
}
int main()
{
test();
test2();
test3();
return boost::report_errors();
}