From ecb41cb1506ca1ff0664e5e1346e5ce35beaba43 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 4 Jul 2007 16:35:44 +0000 Subject: [PATCH] sp_unary_addr_test added (reported by Scott French) [SVN r38137] --- include/boost/detail/sp_counted_impl.hpp | 4 +- test/Jamfile | 1 + test/Jamfile.v2 | 1 + test/sp_unary_addr_test.cpp | 62 ++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 test/sp_unary_addr_test.cpp diff --git a/include/boost/detail/sp_counted_impl.hpp b/include/boost/detail/sp_counted_impl.hpp index 6963f59..919b5dc 100644 --- a/include/boost/detail/sp_counted_impl.hpp +++ b/include/boost/detail/sp_counted_impl.hpp @@ -147,7 +147,7 @@ public: virtual void * get_deleter( std::type_info const & ti ) { - return ti == typeid(D)? &del: 0; + return ti == typeid(D)? &reinterpret_cast( del ): 0; } #if defined(BOOST_SP_USE_STD_ALLOCATOR) @@ -217,7 +217,7 @@ public: virtual void * get_deleter( std::type_info const & ti ) { - return ti == typeid( D )? &d_: 0; + return ti == typeid( D )? &reinterpret_cast( d_ ): 0; } }; diff --git a/test/Jamfile b/test/Jamfile index b3fcac9..71b5df7 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -37,6 +37,7 @@ DEPENDS all : smart_ptr ; [ run shared_ptr_rv_test.cpp ] [ run shared_ptr_move_test.cpp ] [ compile-fail shared_ptr_pv_fail.cpp ] + [ run sp_unary_addr_test.cpp ] ; # this one is too slow to run unless explicitly requested, and ALL diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index b980bfc..e6b49d7 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -32,5 +32,6 @@ import testing ; [ run shared_ptr_rv_test.cpp ] [ run shared_ptr_move_test.cpp ] [ compile-fail shared_ptr_pv_fail.cpp ] + [ run sp_unary_addr_test.cpp ] ; } diff --git a/test/sp_unary_addr_test.cpp b/test/sp_unary_addr_test.cpp new file mode 100644 index 0000000..4522640 --- /dev/null +++ b/test/sp_unary_addr_test.cpp @@ -0,0 +1,62 @@ +// +// sp_unary_addr_test.cpp +// +// Copyright (c) 2007 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 + +struct deleter +{ +private: + + void operator& (); + void operator& () const; + +public: + + int data; + + deleter(): data( 17041 ) + { + } + + void operator()( void * ) + { + } +}; + +struct X +{ +}; + +int main() +{ + X x; + + { + boost::shared_ptr p( &x, deleter() ); + + deleter * q = boost::get_deleter( p ); + + BOOST_TEST( q != 0 ); + BOOST_TEST( q != 0 && q->data == 17041 ); + } + + { + boost::shared_ptr p( &x, deleter(), std::allocator() ); + + deleter * q = boost::get_deleter( p ); + + BOOST_TEST( q != 0 ); + BOOST_TEST( q != 0 && q->data == 17041 ); + } + + return boost::report_errors(); +}