diff --git a/include/boost/enable_shared_from_this.hpp b/include/boost/enable_shared_from_this.hpp index 9a71ae2..f378272 100644 --- a/include/boost/enable_shared_from_this.hpp +++ b/include/boost/enable_shared_from_this.hpp @@ -95,7 +95,7 @@ public: { init_internal_shared_once(); get_deleter(_internal_shared_this)->set_deleter(owner); - owner = dynamic_pointer_cast(_internal_shared_this); + owner.reset( _internal_shared_this, owner.get() ); _internal_shared_this.reset(); _owned = true; } diff --git a/test/esft_regtest.cpp b/test/esft_regtest.cpp index 0e3036c..8bc8cd6 100644 --- a/test/esft_regtest.cpp +++ b/test/esft_regtest.cpp @@ -16,6 +16,7 @@ #include #include #include +#include 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 +{ + virtual ~V() {} + std::string m_; +}; + +struct V2 +{ + virtual ~V2() {} + std::string m2_; +}; + +struct W: V2, V +{ +}; + +void test2() +{ + boost::shared_ptr p( new W ); +} + +void test3() +{ + V * p = new W; + boost::shared_ptr pv( p ); + BOOST_TEST( pv.get() == p ); +} + +int main() +{ + test(); + test2(); + test3(); return boost::report_errors(); }