diff --git a/include/boost/shared_ptr.hpp b/include/boost/shared_ptr.hpp index 7245cac..90a6d5b 100644 --- a/include/boost/shared_ptr.hpp +++ b/include/boost/shared_ptr.hpp @@ -748,16 +748,23 @@ public: } // namespace detail -template D * get_deleter(shared_ptr const & p) +template D * get_deleter( shared_ptr const & p ) { - D *del = detail::basic_get_deleter(p.get_shared_count()); - if(del == 0) + D *del = detail::basic_get_deleter( p.get_shared_count() ); + +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) +#else + + if( del == 0 ) { detail::sp_deleter_wrapper *del_wrapper = detail::basic_get_deleter(p.get_shared_count()); // The following get_deleter method call is fully qualified because // older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter() if(del_wrapper) del = del_wrapper->::boost::detail::sp_deleter_wrapper::get_deleter(); } + +#endif + return del; } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3e10e73..8520861 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -49,5 +49,6 @@ import testing ; [ run sp_convertible_test.cpp ] [ run wp_convertible_test.cpp ] [ run ip_convertible_test.cpp ] + [ run allocate_shared_test.cpp ] ; } diff --git a/test/allocate_shared_test.cpp b/test/allocate_shared_test.cpp new file mode 100644 index 0000000..71ee948 --- /dev/null +++ b/test/allocate_shared_test.cpp @@ -0,0 +1,189 @@ +// allocate_shared_test.cpp +// +// Copyright (c) 2007, 2008 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include + +class X +{ +private: + + X( X const & ); + X & operator=( X const & ); + +public: + + static int instances; + + int v; + + explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 ) + { + ++instances; + } + + ~X() + { + --instances; + } +}; + +int X::instances = 0; + +int main() +{ + { + boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator() ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( *pi == 0 ); + } + + { + boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator(), 5 ); + + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( *pi == 5 ); + } + + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator() ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 0 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5, 6 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5, 6, 7 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5, 6, 7, 8 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + { + boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ); + boost::weak_ptr wp( pi ); + + BOOST_TEST( X::instances == 1 ); + BOOST_TEST( pi.get() != 0 ); + BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); + + pi.reset(); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} diff --git a/test/make_shared_test.cpp b/test/make_shared_test.cpp index efb809f..9930e31 100644 --- a/test/make_shared_test.cpp +++ b/test/make_shared_test.cpp @@ -46,13 +46,6 @@ int main() BOOST_TEST( *pi == 0 ); } - { - boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator() ); - - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( *pi == 0 ); - } - { boost::shared_ptr< int > pi = boost::make_shared< int >( 5 ); @@ -60,13 +53,6 @@ int main() BOOST_TEST( *pi == 5 ); } - { - boost::shared_ptr< int > pi = boost::allocate_shared< int >( std::allocator(), 5 ); - - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( *pi == 5 ); - } - BOOST_TEST( X::instances == 0 ); { @@ -82,20 +68,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator() ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 0 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1 ); boost::weak_ptr wp( pi ); @@ -109,19 +81,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2 ); boost::weak_ptr wp( pi ); @@ -135,19 +94,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1+2 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3 ); boost::weak_ptr wp( pi ); @@ -161,19 +107,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1+2+3 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4 ); boost::weak_ptr wp( pi ); @@ -187,19 +120,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1+2+3+4 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5 ); boost::weak_ptr wp( pi ); @@ -213,19 +133,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1+2+3+4+5 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6 ); boost::weak_ptr wp( pi ); @@ -239,19 +146,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5, 6 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1+2+3+4+5+6 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7 ); boost::weak_ptr wp( pi ); @@ -265,19 +159,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5, 6, 7 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1+2+3+4+5+6+7 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8 ); boost::weak_ptr wp( pi ); @@ -291,19 +172,6 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5, 6, 7, 8 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - { boost::shared_ptr< X > pi = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); boost::weak_ptr wp( pi ); @@ -317,18 +185,5 @@ int main() BOOST_TEST( X::instances == 0 ); } - { - boost::shared_ptr< X > pi = boost::allocate_shared< X >( std::allocator(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ); - boost::weak_ptr wp( pi ); - - BOOST_TEST( X::instances == 1 ); - BOOST_TEST( pi.get() != 0 ); - BOOST_TEST( pi->v == 1+2+3+4+5+6+7+8+9 ); - - pi.reset(); - - BOOST_TEST( X::instances == 0 ); - } - return boost::report_errors(); } diff --git a/test/smart_ptr_test.cpp b/test/smart_ptr_test.cpp index 0c29c9c..8832deb 100644 --- a/test/smart_ptr_test.cpp +++ b/test/smart_ptr_test.cpp @@ -196,6 +196,10 @@ void test() BOOST_TEST( cp.use_count() == 3 ); BOOST_TEST( *cp == 87654 ); +#if defined( BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP ) + using boost::swap; +#endif + boost::shared_ptr cp4; swap( cp2, cp4 ); BOOST_TEST( cp4.use_count() == 3 ); diff --git a/test/sp_unary_addr_test.cpp b/test/sp_unary_addr_test.cpp index 4522640..a4007a2 100644 --- a/test/sp_unary_addr_test.cpp +++ b/test/sp_unary_addr_test.cpp @@ -49,6 +49,9 @@ int main() BOOST_TEST( q != 0 && q->data == 17041 ); } +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) +#else + { boost::shared_ptr p( &x, deleter(), std::allocator() ); @@ -58,5 +61,7 @@ int main() BOOST_TEST( q != 0 && q->data == 17041 ); } +#endif + return boost::report_errors(); }