From 8c15401ea7ff3ba1c92a3e289e6de63633a5668f Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 2 Nov 2012 17:41:33 +0000 Subject: [PATCH] Implement shared_ptr, weak_ptr. Refs #1113. [SVN r81149] --- .../boost/smart_ptr/detail/operator_bool.hpp | 4 +- .../boost/smart_ptr/detail/shared_count.hpp | 2 +- include/boost/smart_ptr/shared_ptr.hpp | 205 +++++++++--- include/boost/smart_ptr/weak_ptr.hpp | 19 +- test/Jamfile.v2 | 57 ++++ test/array_fail_ap_spa_a.cpp | 20 ++ test/array_fail_ap_spa_c.cpp | 20 ++ test/array_fail_ap_spa_ma.cpp | 19 ++ test/array_fail_ap_spa_mc.cpp | 19 ++ test/array_fail_array_access.cpp | 19 ++ test/array_fail_dereference.cpp | 19 ++ test/array_fail_member_access.cpp | 20 ++ test/array_fail_sp_spa_a.cpp | 19 ++ test/array_fail_sp_spa_c.cpp | 19 ++ test/array_fail_sp_spa_ma.cpp | 18 ++ test/array_fail_sp_spa_mc.cpp | 18 ++ test/array_fail_sp_wpa_a.cpp | 20 ++ test/array_fail_sp_wpa_c.cpp | 20 ++ test/array_fail_sp_wpa_ma.cpp | 19 ++ test/array_fail_sp_wpa_mc.cpp | 19 ++ test/array_fail_spa_sp_a.cpp | 19 ++ test/array_fail_spa_sp_c.cpp | 19 ++ test/array_fail_spa_sp_ma.cpp | 18 ++ test/array_fail_spa_sp_mc.cpp | 18 ++ test/array_fail_spa_spa_a.cpp | 23 ++ test/array_fail_spa_spa_c.cpp | 23 ++ test/array_fail_spa_spa_ma.cpp | 22 ++ test/array_fail_spa_spa_mc.cpp | 22 ++ test/array_fail_spa_wp_a.cpp | 20 ++ test/array_fail_spa_wp_c.cpp | 20 ++ test/array_fail_spa_wp_ma.cpp | 19 ++ test/array_fail_spa_wp_mc.cpp | 19 ++ test/array_fail_spa_wpa_a.cpp | 24 ++ test/array_fail_spa_wpa_c.cpp | 24 ++ test/array_fail_spa_wpa_ma.cpp | 23 ++ test/array_fail_spa_wpa_mc.cpp | 23 ++ test/array_fail_up_spa_a.cpp | 20 ++ test/array_fail_up_spa_c.cpp | 20 ++ test/array_fail_up_spa_ma.cpp | 19 ++ test/array_fail_up_spa_mc.cpp | 19 ++ test/array_fail_upa_sp_a.cpp | 20 ++ test/array_fail_upa_sp_c.cpp | 20 ++ test/array_fail_upa_sp_ma.cpp | 19 ++ test/array_fail_upa_sp_mc.cpp | 19 ++ test/array_fail_wp_wpa_a.cpp | 19 ++ test/array_fail_wp_wpa_c.cpp | 19 ++ test/array_fail_wp_wpa_ma.cpp | 18 ++ test/array_fail_wp_wpa_mc.cpp | 18 ++ test/array_fail_wpa_wp_a.cpp | 19 ++ test/array_fail_wpa_wp_c.cpp | 19 ++ test/array_fail_wpa_wp_ma.cpp | 18 ++ test/array_fail_wpa_wp_mc.cpp | 18 ++ test/array_fail_wpa_wpa_a.cpp | 23 ++ test/array_fail_wpa_wpa_c.cpp | 23 ++ test/array_fail_wpa_wpa_ma.cpp | 22 ++ test/array_fail_wpa_wpa_mc.cpp | 22 ++ test/sp_array_test.cpp | 291 ++++++++++++++++++ 57 files changed, 1545 insertions(+), 51 deletions(-) create mode 100644 test/array_fail_ap_spa_a.cpp create mode 100644 test/array_fail_ap_spa_c.cpp create mode 100644 test/array_fail_ap_spa_ma.cpp create mode 100644 test/array_fail_ap_spa_mc.cpp create mode 100644 test/array_fail_array_access.cpp create mode 100644 test/array_fail_dereference.cpp create mode 100644 test/array_fail_member_access.cpp create mode 100644 test/array_fail_sp_spa_a.cpp create mode 100644 test/array_fail_sp_spa_c.cpp create mode 100644 test/array_fail_sp_spa_ma.cpp create mode 100644 test/array_fail_sp_spa_mc.cpp create mode 100644 test/array_fail_sp_wpa_a.cpp create mode 100644 test/array_fail_sp_wpa_c.cpp create mode 100644 test/array_fail_sp_wpa_ma.cpp create mode 100644 test/array_fail_sp_wpa_mc.cpp create mode 100644 test/array_fail_spa_sp_a.cpp create mode 100644 test/array_fail_spa_sp_c.cpp create mode 100644 test/array_fail_spa_sp_ma.cpp create mode 100644 test/array_fail_spa_sp_mc.cpp create mode 100644 test/array_fail_spa_spa_a.cpp create mode 100644 test/array_fail_spa_spa_c.cpp create mode 100644 test/array_fail_spa_spa_ma.cpp create mode 100644 test/array_fail_spa_spa_mc.cpp create mode 100644 test/array_fail_spa_wp_a.cpp create mode 100644 test/array_fail_spa_wp_c.cpp create mode 100644 test/array_fail_spa_wp_ma.cpp create mode 100644 test/array_fail_spa_wp_mc.cpp create mode 100644 test/array_fail_spa_wpa_a.cpp create mode 100644 test/array_fail_spa_wpa_c.cpp create mode 100644 test/array_fail_spa_wpa_ma.cpp create mode 100644 test/array_fail_spa_wpa_mc.cpp create mode 100644 test/array_fail_up_spa_a.cpp create mode 100644 test/array_fail_up_spa_c.cpp create mode 100644 test/array_fail_up_spa_ma.cpp create mode 100644 test/array_fail_up_spa_mc.cpp create mode 100644 test/array_fail_upa_sp_a.cpp create mode 100644 test/array_fail_upa_sp_c.cpp create mode 100644 test/array_fail_upa_sp_ma.cpp create mode 100644 test/array_fail_upa_sp_mc.cpp create mode 100644 test/array_fail_wp_wpa_a.cpp create mode 100644 test/array_fail_wp_wpa_c.cpp create mode 100644 test/array_fail_wp_wpa_ma.cpp create mode 100644 test/array_fail_wp_wpa_mc.cpp create mode 100644 test/array_fail_wpa_wp_a.cpp create mode 100644 test/array_fail_wpa_wp_c.cpp create mode 100644 test/array_fail_wpa_wp_ma.cpp create mode 100644 test/array_fail_wpa_wp_mc.cpp create mode 100644 test/array_fail_wpa_wpa_a.cpp create mode 100644 test/array_fail_wpa_wpa_c.cpp create mode 100644 test/array_fail_wpa_wpa_ma.cpp create mode 100644 test/array_fail_wpa_wpa_mc.cpp create mode 100644 test/sp_array_test.cpp diff --git a/include/boost/smart_ptr/detail/operator_bool.hpp b/include/boost/smart_ptr/detail/operator_bool.hpp index 842a05d..1d5be11 100644 --- a/include/boost/smart_ptr/detail/operator_bool.hpp +++ b/include/boost/smart_ptr/detail/operator_bool.hpp @@ -31,7 +31,7 @@ ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \ ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) ) - typedef T * (this_type::*unspecified_bool_type)() const; + typedef element_type * (this_type::*unspecified_bool_type)() const; operator unspecified_bool_type() const // never throws { @@ -40,7 +40,7 @@ #else - typedef T * this_type::*unspecified_bool_type; + typedef element_type * this_type::*unspecified_bool_type; operator unspecified_bool_type() const // never throws { diff --git a/include/boost/smart_ptr/detail/shared_count.hpp b/include/boost/smart_ptr/detail/shared_count.hpp index 2c99f02..be4f65b 100644 --- a/include/boost/smart_ptr/detail/shared_count.hpp +++ b/include/boost/smart_ptr/detail/shared_count.hpp @@ -347,7 +347,7 @@ public: typedef typename sp_convert_reference::type D2; D2 d2( r.get_deleter() ); - pi_ = new sp_counted_impl_pd< Y*, D2 >( r.get(), d2 ); + pi_ = new sp_counted_impl_pd< typename std::unique_ptr::pointer, D2 >( r.get(), d2 ); #ifdef BOOST_NO_EXCEPTIONS diff --git a/include/boost/smart_ptr/shared_ptr.hpp b/include/boost/smart_ptr/shared_ptr.hpp index 924f621..2bd721a 100644 --- a/include/boost/smart_ptr/shared_ptr.hpp +++ b/include/boost/smart_ptr/shared_ptr.hpp @@ -67,34 +67,93 @@ struct const_cast_tag {}; struct dynamic_cast_tag {}; struct polymorphic_cast_tag {}; -template struct shared_ptr_traits +// sp_element, element_type + +template< class T > struct sp_element { - typedef T & reference; + typedef T type; }; -template<> struct shared_ptr_traits +#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +template< class T > struct sp_element< T[] > { - typedef void reference; + typedef T type; +}; + +#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +// sp_dereference, return type of operator* + +template< class T > struct sp_dereference +{ + typedef T & type; +}; + +template<> struct sp_dereference< void > +{ + typedef void type; }; #if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS) -template<> struct shared_ptr_traits +template<> struct sp_dereference< void const > { - typedef void reference; + typedef void type; }; -template<> struct shared_ptr_traits +template<> struct sp_dereference< void volatile > { - typedef void reference; + typedef void type; }; -template<> struct shared_ptr_traits +template<> struct sp_dereference< void const volatile > { - typedef void reference; + typedef void type; }; -#endif +#endif // !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS) + +#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +template< class T > struct sp_dereference< T[] > +{ + typedef void type; +}; + +#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +// sp_member_access, return type of operator-> + +template< class T > struct sp_member_access +{ + typedef T * type; +}; + +#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +template< class T > struct sp_member_access< T[] > +{ + typedef void type; +}; + +#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +// sp_array_access, return type of operator[] + +template< class T > struct sp_array_access +{ + typedef void type; +}; + +#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +template< class T > struct sp_array_access< T[] > +{ + typedef T & type; +}; + +#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) // enable_shared_from_this support @@ -144,6 +203,47 @@ template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R #endif +// sp_assert_convertible + +template< class T > inline void sp_assert_convertible( T * ) +{ +} + +// pointer constructor helper + +template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T > * ppx, Y * p, boost::detail::shared_count & pn ) +{ + boost::detail::shared_count( p ).swap( pn ); + boost::detail::sp_enable_shared_from_this( ppx, p, p ); +} + +#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * p, boost::detail::shared_count & pn ) +{ + sp_assert_convertible< T[] >( static_cast< Y (*) [] >( 0 ) ); + + boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn ); +} + +#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +// deleter constructor helper + +template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T > * ppx, Y * p ) +{ + boost::detail::sp_enable_shared_from_this( ppx, p, p ); +} + +#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + +template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * /*p*/ ) +{ + sp_assert_convertible< T[] >( static_cast< Y (*) [] >( 0 ) ); +} + +#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) + } // namespace detail @@ -164,19 +264,16 @@ private: public: - typedef T element_type; - typedef T value_type; - typedef T * pointer; - typedef typename boost::detail::shared_ptr_traits::reference reference; + typedef typename boost::detail::sp_element< T >::type element_type; - shared_ptr(): px(0), pn() // never throws in 1.30+ + shared_ptr(): px( 0 ), pn() // never throws in 1.30+ { } template - explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete + explicit shared_ptr( Y * p ): px( p ), pn() // Y must be complete { - boost::detail::sp_enable_shared_from_this( this, p, p ); + boost::detail::sp_pointer_construct( this, p, pn ); } // @@ -185,16 +282,16 @@ public: // shared_ptr will release p by calling d(p) // - template shared_ptr(Y * p, D d): px(p), pn(p, d) + template shared_ptr( Y * p, D d ): px( p ), pn( p, d ) { - boost::detail::sp_enable_shared_from_this( this, p, p ); + boost::detail::sp_deleter_construct( this, p ); } // As above, but with allocator. A's copy constructor shall not throw. template shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a ) { - boost::detail::sp_enable_shared_from_this( this, p, p ); + boost::detail::sp_deleter_construct( this, p ); } // generated copy constructor, destructor are fine... @@ -210,8 +307,10 @@ public: #endif template - explicit shared_ptr(weak_ptr const & r): pn(r.pn) // may throw + explicit shared_ptr( weak_ptr const & r ): pn( r.pn ) // may throw { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); + // it is now safe to copy r.px, as pn(r.pn) did not throw px = r.px; } @@ -237,11 +336,12 @@ public: #endif : px( r.px ), pn( r.pn ) // never throws { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); } // aliasing template< class Y > - shared_ptr( shared_ptr const & r, T * p ): px( p ), pn( r.pn ) // never throws + shared_ptr( shared_ptr const & r, element_type * p ): px( p ), pn( r.pn ) // never throws { } @@ -278,9 +378,12 @@ public: template explicit shared_ptr(std::auto_ptr & r): px(r.get()), pn() { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); + Y * tmp = r.get(); pn = boost::detail::shared_count(r); - boost::detail::sp_enable_shared_from_this( this, tmp, tmp ); + + boost::detail::sp_deleter_construct( this, tmp ); } #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) @@ -288,11 +391,15 @@ public: template explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr::type = 0 ): px( r.get() ), pn() { - typename Ap::element_type * tmp = r.get(); - pn = boost::detail::shared_count( r ); - boost::detail::sp_enable_shared_from_this( this, tmp, tmp ); - } + typedef typename Ap::element_type Y; + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); + + Y * tmp = r.get(); + pn = boost::detail::shared_count( r ); + + boost::detail::sp_deleter_construct( this, tmp ); + } #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION @@ -301,11 +408,14 @@ public: #if !defined( BOOST_NO_CXX11_SMART_PTR ) template< class Y, class D > - shared_ptr( std::unique_ptr< Y, D > && r): px( r.get() ), pn() + shared_ptr( std::unique_ptr< Y, D > && r ): px( r.get() ), pn() { - Y * tmp = r.get(); + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); + + typename std::unique_ptr< Y, D >::pointer tmp = r.get(); pn = boost::detail::shared_count( r ); - boost::detail::sp_enable_shared_from_this( this, tmp, tmp ); + + boost::detail::sp_deleter_construct( this, tmp ); } #endif @@ -347,7 +457,6 @@ public: return *this; } - #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #endif // BOOST_NO_AUTO_PTR @@ -374,6 +483,8 @@ public: #endif : px( r.px ), pn() // never throws { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); + pn.swap( r.pn ); r.px = 0; } @@ -398,10 +509,10 @@ public: this_type().swap(*this); } - template void reset(Y * p) // Y must be complete + template void reset( Y * p ) // Y must be complete { - BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors - this_type(p).swap(*this); + BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors + this_type( p ).swap( *this ); } template void reset( Y * p, D d ) @@ -414,24 +525,32 @@ public: this_type( p, d, a ).swap( *this ); } - template void reset( shared_ptr const & r, T * p ) + template void reset( shared_ptr const & r, element_type * p ) { this_type( r, p ).swap( *this ); } - reference operator* () const // never throws + typename boost::detail::sp_dereference< T >::type operator* () const // never throws { - BOOST_ASSERT(px != 0); + BOOST_ASSERT( px != 0 ); return *px; } - T * operator-> () const // never throws + typename boost::detail::sp_member_access< T >::type operator-> () const // never throws { - BOOST_ASSERT(px != 0); + BOOST_ASSERT( px != 0 ); return px; } - T * get() const // never throws + typename boost::detail::sp_array_access< T >::type operator[] ( std::ptrdiff_t i ) const // never throws + { + BOOST_ASSERT( px != 0 ); + BOOST_ASSERT( i >= 0 ); + + return px[ i ]; + } + + element_type * get() const // never throws { return px; } @@ -449,7 +568,7 @@ public: return pn.use_count(); } - void swap(shared_ptr & other) // never throws + void swap( shared_ptr & other ) // never throws { std::swap(px, other.px); pn.swap(other.pn); @@ -488,7 +607,7 @@ private: #endif - T * px; // contained pointer + element_type * px; // contained pointer boost::detail::shared_count pn; // reference counter }; // shared_ptr diff --git a/include/boost/smart_ptr/weak_ptr.hpp b/include/boost/smart_ptr/weak_ptr.hpp index 5391910..f33116b 100644 --- a/include/boost/smart_ptr/weak_ptr.hpp +++ b/include/boost/smart_ptr/weak_ptr.hpp @@ -29,7 +29,7 @@ private: public: - typedef T element_type; + typedef typename boost::detail::sp_element< T >::type element_type; weak_ptr(): px(0), pn() // never throws in 1.30+ { @@ -83,6 +83,7 @@ public: #endif : px(r.lock().get()), pn(r.pn) // never throws { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); } #if defined( BOOST_HAS_RVALUE_REFS ) @@ -99,6 +100,7 @@ public: #endif : px( r.lock().get() ), pn( static_cast< boost::detail::weak_count && >( r.pn ) ) // never throws { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); r.px = 0; } @@ -130,15 +132,19 @@ public: #endif : px( r.px ), pn( r.pn ) // never throws { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); } #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300) template - weak_ptr & operator=(weak_ptr const & r) // never throws + weak_ptr & operator=( weak_ptr const & r ) // never throws { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); + px = r.lock().get(); pn = r.pn; + return *this; } @@ -154,10 +160,13 @@ public: #endif template - weak_ptr & operator=(shared_ptr const & r) // never throws + weak_ptr & operator=( shared_ptr const & r ) // never throws { + boost::detail::sp_assert_convertible< T >( static_cast< Y* >( 0 ) ); + px = r.px; pn = r.pn; + return *this; } @@ -165,7 +174,7 @@ public: shared_ptr lock() const // never throws { - return shared_ptr( *this, boost::detail::sp_nothrow_tag() ); + return shared_ptr( *this, boost::detail::sp_nothrow_tag() ); } long use_count() const // never throws @@ -223,7 +232,7 @@ private: #endif - T * px; // contained pointer + element_type * px; // contained pointer boost::detail::weak_count pn; // reference counter }; // weak_ptr diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1df2a3e..c638d92 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -70,5 +70,62 @@ import testing ; [ run ip_hash_test.cpp ] [ run owner_less_test.cpp ] [ run sp_unique_ptr_test.cpp ] + [ run sp_array_test.cpp ] + + [ compile-fail array_fail_spa_sp_c.cpp ] + [ compile-fail array_fail_sp_spa_c.cpp ] + [ compile-fail array_fail_spa_spa_c.cpp ] + [ compile-fail array_fail_spa_wp_c.cpp ] + [ compile-fail array_fail_sp_wpa_c.cpp ] + [ compile-fail array_fail_spa_wpa_c.cpp ] + [ compile-fail array_fail_wpa_wp_c.cpp ] + [ compile-fail array_fail_wp_wpa_c.cpp ] + [ compile-fail array_fail_wpa_wpa_c.cpp ] + [ compile-fail array_fail_ap_spa_c.cpp ] + [ compile-fail array_fail_upa_sp_c.cpp ] + [ compile-fail array_fail_up_spa_c.cpp ] + + [ compile-fail array_fail_spa_sp_mc.cpp ] + [ compile-fail array_fail_sp_spa_mc.cpp ] + [ compile-fail array_fail_spa_spa_mc.cpp ] + [ compile-fail array_fail_spa_wp_mc.cpp ] + [ compile-fail array_fail_sp_wpa_mc.cpp ] + [ compile-fail array_fail_spa_wpa_mc.cpp ] + [ compile-fail array_fail_wpa_wp_mc.cpp ] + [ compile-fail array_fail_wp_wpa_mc.cpp ] + [ compile-fail array_fail_wpa_wpa_mc.cpp ] + [ compile-fail array_fail_ap_spa_mc.cpp ] + [ compile-fail array_fail_upa_sp_mc.cpp ] + [ compile-fail array_fail_up_spa_mc.cpp ] + + [ compile-fail array_fail_spa_sp_a.cpp ] + [ compile-fail array_fail_sp_spa_a.cpp ] + [ compile-fail array_fail_spa_spa_a.cpp ] + [ compile-fail array_fail_spa_wp_a.cpp ] + [ compile-fail array_fail_sp_wpa_a.cpp ] + [ compile-fail array_fail_spa_wpa_a.cpp ] + [ compile-fail array_fail_wpa_wp_a.cpp ] + [ compile-fail array_fail_wp_wpa_a.cpp ] + [ compile-fail array_fail_wpa_wpa_a.cpp ] + [ compile-fail array_fail_ap_spa_a.cpp ] + [ compile-fail array_fail_upa_sp_a.cpp ] + [ compile-fail array_fail_up_spa_a.cpp ] + + [ compile-fail array_fail_spa_sp_ma.cpp ] + [ compile-fail array_fail_sp_spa_ma.cpp ] + [ compile-fail array_fail_spa_spa_ma.cpp ] + [ compile-fail array_fail_spa_wp_ma.cpp ] + [ compile-fail array_fail_sp_wpa_ma.cpp ] + [ compile-fail array_fail_spa_wpa_ma.cpp ] + [ compile-fail array_fail_wpa_wp_ma.cpp ] + [ compile-fail array_fail_wp_wpa_ma.cpp ] + [ compile-fail array_fail_wpa_wpa_ma.cpp ] + [ compile-fail array_fail_ap_spa_ma.cpp ] + [ compile-fail array_fail_upa_sp_ma.cpp ] + [ compile-fail array_fail_up_spa_ma.cpp ] + + [ compile-fail array_fail_dereference.cpp ] + [ compile-fail array_fail_member_access.cpp ] + [ compile-fail array_fail_array_access.cpp ] ; } diff --git a/test/array_fail_ap_spa_a.cpp b/test/array_fail_ap_spa_a.cpp new file mode 100644 index 0000000..0524827 --- /dev/null +++ b/test/array_fail_ap_spa_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + std::auto_ptr px; + boost::shared_ptr px2; px2 = px; +} diff --git a/test/array_fail_ap_spa_c.cpp b/test/array_fail_ap_spa_c.cpp new file mode 100644 index 0000000..bc76316 --- /dev/null +++ b/test/array_fail_ap_spa_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + std::auto_ptr px; + boost::shared_ptr px2( px ); +} diff --git a/test/array_fail_ap_spa_ma.cpp b/test/array_fail_ap_spa_ma.cpp new file mode 100644 index 0000000..e26a548 --- /dev/null +++ b/test/array_fail_ap_spa_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2; px2 = std::auto_ptr(); +} diff --git a/test/array_fail_ap_spa_mc.cpp b/test/array_fail_ap_spa_mc.cpp new file mode 100644 index 0000000..d53eeff --- /dev/null +++ b/test/array_fail_ap_spa_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2(( std::auto_ptr() )); +} diff --git a/test/array_fail_array_access.cpp b/test/array_fail_array_access.cpp new file mode 100644 index 0000000..abfacbe --- /dev/null +++ b/test/array_fail_array_access.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px( new X ); + px[ 0 ]; +} diff --git a/test/array_fail_dereference.cpp b/test/array_fail_dereference.cpp new file mode 100644 index 0000000..081d5b4 --- /dev/null +++ b/test/array_fail_dereference.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px( new X[ 1 ] ); + *px; +} diff --git a/test/array_fail_member_access.cpp b/test/array_fail_member_access.cpp new file mode 100644 index 0000000..8051ad1 --- /dev/null +++ b/test/array_fail_member_access.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ + int m; +}; + +int main() +{ + boost::shared_ptr px( new X[ 1 ] ); + px->m = 0; +} diff --git a/test/array_fail_sp_spa_a.cpp b/test/array_fail_sp_spa_a.cpp new file mode 100644 index 0000000..e1e2bb6 --- /dev/null +++ b/test/array_fail_sp_spa_a.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::shared_ptr px2; px2 = px; +} diff --git a/test/array_fail_sp_spa_c.cpp b/test/array_fail_sp_spa_c.cpp new file mode 100644 index 0000000..c65df88 --- /dev/null +++ b/test/array_fail_sp_spa_c.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::shared_ptr px2( px ); +} diff --git a/test/array_fail_sp_spa_ma.cpp b/test/array_fail_sp_spa_ma.cpp new file mode 100644 index 0000000..a1253a0 --- /dev/null +++ b/test/array_fail_sp_spa_ma.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2; px2 = boost::shared_ptr(); +} diff --git a/test/array_fail_sp_spa_mc.cpp b/test/array_fail_sp_spa_mc.cpp new file mode 100644 index 0000000..75c014c --- /dev/null +++ b/test/array_fail_sp_spa_mc.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2(( boost::shared_ptr() )); +} diff --git a/test/array_fail_sp_wpa_a.cpp b/test/array_fail_sp_wpa_a.cpp new file mode 100644 index 0000000..8b88512 --- /dev/null +++ b/test/array_fail_sp_wpa_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::weak_ptr px2; px2 = px; +} diff --git a/test/array_fail_sp_wpa_c.cpp b/test/array_fail_sp_wpa_c.cpp new file mode 100644 index 0000000..fc7cd5b --- /dev/null +++ b/test/array_fail_sp_wpa_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::weak_ptr px2( px ); +} diff --git a/test/array_fail_sp_wpa_ma.cpp b/test/array_fail_sp_wpa_ma.cpp new file mode 100644 index 0000000..578e10b --- /dev/null +++ b/test/array_fail_sp_wpa_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px2; px2 = boost::shared_ptr(); +} diff --git a/test/array_fail_sp_wpa_mc.cpp b/test/array_fail_sp_wpa_mc.cpp new file mode 100644 index 0000000..ca62eaf --- /dev/null +++ b/test/array_fail_sp_wpa_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px2(( boost::shared_ptr() )); +} diff --git a/test/array_fail_spa_sp_a.cpp b/test/array_fail_spa_sp_a.cpp new file mode 100644 index 0000000..4d6d323 --- /dev/null +++ b/test/array_fail_spa_sp_a.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::shared_ptr px2; px2 = px; +} diff --git a/test/array_fail_spa_sp_c.cpp b/test/array_fail_spa_sp_c.cpp new file mode 100644 index 0000000..9015483 --- /dev/null +++ b/test/array_fail_spa_sp_c.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::shared_ptr px2( px ); +} diff --git a/test/array_fail_spa_sp_ma.cpp b/test/array_fail_spa_sp_ma.cpp new file mode 100644 index 0000000..6511887 --- /dev/null +++ b/test/array_fail_spa_sp_ma.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2; px2 = boost::shared_ptr(); +} diff --git a/test/array_fail_spa_sp_mc.cpp b/test/array_fail_spa_sp_mc.cpp new file mode 100644 index 0000000..46f6e30 --- /dev/null +++ b/test/array_fail_spa_sp_mc.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2(( boost::shared_ptr() )); +} diff --git a/test/array_fail_spa_spa_a.cpp b/test/array_fail_spa_spa_a.cpp new file mode 100644 index 0000000..edb248d --- /dev/null +++ b/test/array_fail_spa_spa_a.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::shared_ptr px2; px2 = px; +} diff --git a/test/array_fail_spa_spa_c.cpp b/test/array_fail_spa_spa_c.cpp new file mode 100644 index 0000000..a1833ee --- /dev/null +++ b/test/array_fail_spa_spa_c.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::shared_ptr px2( px ); +} diff --git a/test/array_fail_spa_spa_ma.cpp b/test/array_fail_spa_spa_ma.cpp new file mode 100644 index 0000000..8c81693 --- /dev/null +++ b/test/array_fail_spa_spa_ma.cpp @@ -0,0 +1,22 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr px2; px2 = boost::shared_ptr(); +} diff --git a/test/array_fail_spa_spa_mc.cpp b/test/array_fail_spa_spa_mc.cpp new file mode 100644 index 0000000..606d937 --- /dev/null +++ b/test/array_fail_spa_spa_mc.cpp @@ -0,0 +1,22 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr px2(( boost::shared_ptr() )); +} diff --git a/test/array_fail_spa_wp_a.cpp b/test/array_fail_spa_wp_a.cpp new file mode 100644 index 0000000..14c122e --- /dev/null +++ b/test/array_fail_spa_wp_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::weak_ptr px2; px2 = px; +} diff --git a/test/array_fail_spa_wp_c.cpp b/test/array_fail_spa_wp_c.cpp new file mode 100644 index 0000000..9c22a5b --- /dev/null +++ b/test/array_fail_spa_wp_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::weak_ptr px2( px ); +} diff --git a/test/array_fail_spa_wp_ma.cpp b/test/array_fail_spa_wp_ma.cpp new file mode 100644 index 0000000..49c1eb0 --- /dev/null +++ b/test/array_fail_spa_wp_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px2; px2 = boost::shared_ptr(); +} diff --git a/test/array_fail_spa_wp_mc.cpp b/test/array_fail_spa_wp_mc.cpp new file mode 100644 index 0000000..738946c --- /dev/null +++ b/test/array_fail_spa_wp_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px2(( boost::shared_ptr() )); +} diff --git a/test/array_fail_spa_wpa_a.cpp b/test/array_fail_spa_wpa_a.cpp new file mode 100644 index 0000000..9c65f1c --- /dev/null +++ b/test/array_fail_spa_wpa_a.cpp @@ -0,0 +1,24 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::weak_ptr px2; px2 = px; +} diff --git a/test/array_fail_spa_wpa_c.cpp b/test/array_fail_spa_wpa_c.cpp new file mode 100644 index 0000000..ff2ae22 --- /dev/null +++ b/test/array_fail_spa_wpa_c.cpp @@ -0,0 +1,24 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::shared_ptr px; + boost::weak_ptr px2( px ); +} diff --git a/test/array_fail_spa_wpa_ma.cpp b/test/array_fail_spa_wpa_ma.cpp new file mode 100644 index 0000000..cb2725e --- /dev/null +++ b/test/array_fail_spa_wpa_ma.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr px2; px2 = boost::shared_ptr(); +} diff --git a/test/array_fail_spa_wpa_mc.cpp b/test/array_fail_spa_wpa_mc.cpp new file mode 100644 index 0000000..9b07933 --- /dev/null +++ b/test/array_fail_spa_wpa_mc.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr px2(( boost::shared_ptr() )); +} diff --git a/test/array_fail_up_spa_a.cpp b/test/array_fail_up_spa_a.cpp new file mode 100644 index 0000000..8b9f246 --- /dev/null +++ b/test/array_fail_up_spa_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + std::unique_ptr px; + boost::shared_ptr px2; px2 = px; +} diff --git a/test/array_fail_up_spa_c.cpp b/test/array_fail_up_spa_c.cpp new file mode 100644 index 0000000..1bbc5c0 --- /dev/null +++ b/test/array_fail_up_spa_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + std::unique_ptr px; + boost::shared_ptr px2( px ); +} diff --git a/test/array_fail_up_spa_ma.cpp b/test/array_fail_up_spa_ma.cpp new file mode 100644 index 0000000..fcd612d --- /dev/null +++ b/test/array_fail_up_spa_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2; px2 = std::unique_ptr(); +} diff --git a/test/array_fail_up_spa_mc.cpp b/test/array_fail_up_spa_mc.cpp new file mode 100644 index 0000000..6a20d6e --- /dev/null +++ b/test/array_fail_up_spa_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2(( std::unique_ptr() )); +} diff --git a/test/array_fail_upa_sp_a.cpp b/test/array_fail_upa_sp_a.cpp new file mode 100644 index 0000000..b44e07e --- /dev/null +++ b/test/array_fail_upa_sp_a.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + std::unique_ptr px; + boost::shared_ptr px2; px2 = px; +} diff --git a/test/array_fail_upa_sp_c.cpp b/test/array_fail_upa_sp_c.cpp new file mode 100644 index 0000000..fe62044 --- /dev/null +++ b/test/array_fail_upa_sp_c.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + std::unique_ptr px; + boost::shared_ptr px2( px ); +} diff --git a/test/array_fail_upa_sp_ma.cpp b/test/array_fail_upa_sp_ma.cpp new file mode 100644 index 0000000..1b2a2b2 --- /dev/null +++ b/test/array_fail_upa_sp_ma.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2; px2 = std::unique_ptr(); +} diff --git a/test/array_fail_upa_sp_mc.cpp b/test/array_fail_upa_sp_mc.cpp new file mode 100644 index 0000000..d314a01 --- /dev/null +++ b/test/array_fail_upa_sp_mc.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::shared_ptr px2(( std::unique_ptr() )); +} diff --git a/test/array_fail_wp_wpa_a.cpp b/test/array_fail_wp_wpa_a.cpp new file mode 100644 index 0000000..ea82eb9 --- /dev/null +++ b/test/array_fail_wp_wpa_a.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px; + boost::weak_ptr px2; px2 = px; +} diff --git a/test/array_fail_wp_wpa_c.cpp b/test/array_fail_wp_wpa_c.cpp new file mode 100644 index 0000000..9f5609c --- /dev/null +++ b/test/array_fail_wp_wpa_c.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px; + boost::weak_ptr px2( px ); +} diff --git a/test/array_fail_wp_wpa_ma.cpp b/test/array_fail_wp_wpa_ma.cpp new file mode 100644 index 0000000..79af4d7 --- /dev/null +++ b/test/array_fail_wp_wpa_ma.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px2; px2 = boost::weak_ptr(); +} diff --git a/test/array_fail_wp_wpa_mc.cpp b/test/array_fail_wp_wpa_mc.cpp new file mode 100644 index 0000000..18a9d8a --- /dev/null +++ b/test/array_fail_wp_wpa_mc.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px2(( boost::weak_ptr() )); +} diff --git a/test/array_fail_wpa_wp_a.cpp b/test/array_fail_wpa_wp_a.cpp new file mode 100644 index 0000000..19d0026 --- /dev/null +++ b/test/array_fail_wpa_wp_a.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px; + boost::weak_ptr px2; px2 = px; +} diff --git a/test/array_fail_wpa_wp_c.cpp b/test/array_fail_wpa_wp_c.cpp new file mode 100644 index 0000000..d4b75dd --- /dev/null +++ b/test/array_fail_wpa_wp_c.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px; + boost::weak_ptr px2( px ); +} diff --git a/test/array_fail_wpa_wp_ma.cpp b/test/array_fail_wpa_wp_ma.cpp new file mode 100644 index 0000000..5c33c8b --- /dev/null +++ b/test/array_fail_wpa_wp_ma.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px2; px2 = boost::weak_ptr(); +} diff --git a/test/array_fail_wpa_wp_mc.cpp b/test/array_fail_wpa_wp_mc.cpp new file mode 100644 index 0000000..8375e6b --- /dev/null +++ b/test/array_fail_wpa_wp_mc.cpp @@ -0,0 +1,18 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +int main() +{ + boost::weak_ptr px2(( boost::weak_ptr() )); +} diff --git a/test/array_fail_wpa_wpa_a.cpp b/test/array_fail_wpa_wpa_a.cpp new file mode 100644 index 0000000..29aeaa6 --- /dev/null +++ b/test/array_fail_wpa_wpa_a.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr px; + boost::weak_ptr px2; px2 = px; +} diff --git a/test/array_fail_wpa_wpa_c.cpp b/test/array_fail_wpa_wpa_c.cpp new file mode 100644 index 0000000..98a574e --- /dev/null +++ b/test/array_fail_wpa_wpa_c.cpp @@ -0,0 +1,23 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr px; + boost::weak_ptr px2( px ); +} diff --git a/test/array_fail_wpa_wpa_ma.cpp b/test/array_fail_wpa_wpa_ma.cpp new file mode 100644 index 0000000..eb638de --- /dev/null +++ b/test/array_fail_wpa_wpa_ma.cpp @@ -0,0 +1,22 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr px2; px2 = boost::weak_ptr(); +} diff --git a/test/array_fail_wpa_wpa_mc.cpp b/test/array_fail_wpa_wpa_mc.cpp new file mode 100644 index 0000000..77d4f75 --- /dev/null +++ b/test/array_fail_wpa_wpa_mc.cpp @@ -0,0 +1,22 @@ +// +// Copyright (c) 2012 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 + +struct X +{ +}; + +struct Y: public X +{ +}; + +int main() +{ + boost::weak_ptr px2(( boost::weak_ptr() )); +} diff --git a/test/sp_array_test.cpp b/test/sp_array_test.cpp new file mode 100644 index 0000000..eab918e --- /dev/null +++ b/test/sp_array_test.cpp @@ -0,0 +1,291 @@ +// +// sp_array_test.cpp +// +// Copyright (c) 2012 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 +#include +#include + +class X: public boost::enable_shared_from_this< X > +{ +public: + + static int allocations; + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + + void* operator new[]( std::size_t n ) + { + ++allocations; + return ::operator new[]( n ); + } + + void operator delete[]( void* p ) + { + --allocations; + ::operator delete[]( p ); + } + +private: + + X( X const& ); + X& operator=( X const& ); +}; + +int X::allocations = 0; +int X::instances = 0; + +template< class T> class array_deleter +{ +public: + + static int calls; + + void operator()( T * p ) const + { + ++calls; + delete[] p; + } + +private: + + template< class Y > void operator()( Y * p ) const; +}; + +template< class T > int array_deleter< T >::calls = 0; + +int main() +{ + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + { + boost::shared_ptr px; + BOOST_TEST( !px ); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + boost::shared_ptr px2( new X[ 3 ] ); + BOOST_TEST( px2 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + { + X & rx = px2[ 0 ]; + BOOST_TEST( &rx == px2.get() ); + } + + boost::shared_ptr px3( px2 ); + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + { + X const & rx = px3[ 1 ]; + BOOST_TEST( &rx == px3.get() + 1 ); + } + + px3.reset(); + px3 = px2; + BOOST_TEST( px3 == px2 ); + BOOST_TEST( !( px2 < px3 ) && !( px3 < px2 ) ); + + boost::shared_ptr px4( px2 ); + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + { + X volatile & rx = px4[ 2 ]; + BOOST_TEST( &rx == px4.get() + 2 ); + } + + px4.reset(); + px4 = px2; + BOOST_TEST( px4 == px2 ); + BOOST_TEST( !( px2 < px4 ) && !( px4 < px2 ) ); + + boost::shared_ptr px5( px2 ); + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + px5.reset(); + px5 = px2; + BOOST_TEST( px5 == px2 ); + BOOST_TEST( !( px2 < px5 ) && !( px5 < px2 ) ); + + boost::weak_ptr wp( px ); + BOOST_TEST( wp.lock() == px ); + + boost::weak_ptr wp2( px2 ); + BOOST_TEST( wp2.lock() == px2 ); + + wp2.reset(); + wp2 = px2; + BOOST_TEST( wp2.lock() == px2 ); + + boost::weak_ptr wp3( px2 ); + BOOST_TEST( wp3.lock() == px2 ); + + wp3.reset(); + wp3 = px2; + BOOST_TEST( wp3.lock() == px2 ); + + boost::weak_ptr wp4( px2 ); + BOOST_TEST( wp4.lock() == px2 ); + + wp4.reset(); + wp4 = px2; + BOOST_TEST( wp4.lock() == px2 ); + + boost::weak_ptr wp5( px2 ); + BOOST_TEST( wp5.lock() == px2 ); + + wp5.reset(); + wp5 = px2; + BOOST_TEST( wp5.lock() == px2 ); + + px2.reset(); + + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 3 ); + + px3.reset(); + px4.reset(); + px5.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + + BOOST_TEST( wp2.lock() == 0 ); + BOOST_TEST( wp3.lock() == 0 ); + BOOST_TEST( wp4.lock() == 0 ); + BOOST_TEST( wp5.lock() == 0 ); + } + +#if !defined( BOOST_NO_CXX11_SMART_PTR ) + + { + std::unique_ptr px( new X[ 4 ] ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + + boost::shared_ptr px2( std::move( px ) ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + BOOST_TEST( px.get() == 0 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + + px2.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + } + + { + std::unique_ptr px( new X[ 4 ] ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + + boost::shared_ptr px2; + px2 = std::move( px ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 4 ); + BOOST_TEST( px.get() == 0 ); + + try + { + px2[0].shared_from_this(); + BOOST_ERROR( "px2[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + + px2.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + } + +#endif + + { + boost::shared_ptr px( new X[ 5 ], array_deleter< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 5 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 1 ); + } + + { + boost::shared_ptr px( new X[ 6 ], array_deleter< X >(), std::allocator< X >() ); + BOOST_TEST( X::allocations == 1 ); + BOOST_TEST( X::instances == 6 ); + + try + { + px[0].shared_from_this(); + BOOST_ERROR( "px[0].shared_from_this() failed to throw" ); + } + catch( boost::bad_weak_ptr const& ) + { + } + + px.reset(); + + BOOST_TEST( X::allocations == 0 ); + BOOST_TEST( X::instances == 0 ); + BOOST_TEST( array_deleter< X >::calls == 2 ); + } + + return boost::report_errors(); +}