From 5d564a2f01f0caf9e11261b988dbef1abaf91392 Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Thu, 24 Jan 2002 19:16:12 +0000 Subject: [PATCH] Add a self-assignment assert to reset(). Also add an overload of reset to allow resetting to a new pointer with a new deletion function. [SVN r12491] --- include/boost/detail/shared_array_nmt.hpp | 1 + include/boost/detail/shared_ptr_nmt.hpp | 1 + include/boost/shared_array.hpp | 1 + include/boost/shared_ptr.hpp | 8 +++++++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/boost/detail/shared_array_nmt.hpp b/include/boost/detail/shared_array_nmt.hpp index e5137a3..570af13 100644 --- a/include/boost/detail/shared_array_nmt.hpp +++ b/include/boost/detail/shared_array_nmt.hpp @@ -72,6 +72,7 @@ public: void reset(T * p = 0) { + BOOST_ASSERT(p == 0 || p != px); shared_array(p).swap(*this); } diff --git a/include/boost/detail/shared_ptr_nmt.hpp b/include/boost/detail/shared_ptr_nmt.hpp index 8b268a2..5364e77 100644 --- a/include/boost/detail/shared_ptr_nmt.hpp +++ b/include/boost/detail/shared_ptr_nmt.hpp @@ -91,6 +91,7 @@ public: void reset(T * p = 0) { + BOOST_ASSERT(p == 0 || p != px); shared_ptr(p).swap(*this); } diff --git a/include/boost/shared_array.hpp b/include/boost/shared_array.hpp index 85741b2..5098dee 100644 --- a/include/boost/shared_array.hpp +++ b/include/boost/shared_array.hpp @@ -71,6 +71,7 @@ public: void reset(T * p = 0) { + BOOST_ASSERT(p == 0 || p != px); this_type(p).swap(*this); } diff --git a/include/boost/shared_ptr.hpp b/include/boost/shared_ptr.hpp index 996a1b5..db75b9e 100644 --- a/include/boost/shared_ptr.hpp +++ b/include/boost/shared_ptr.hpp @@ -33,7 +33,7 @@ #ifdef BOOST_MSVC // moved here to work around VC++ compiler crash # pragma warning(push) # pragma warning(disable:4284) // odd return type for operator-> -#endif +#endif namespace boost { @@ -144,9 +144,15 @@ public: void reset(T * p = 0) { + BOOST_ASSERT(p == 0 || p != px); this_type(p).swap(*this); } + template void reset(T * p, D d) + { + this_type(p, d).swap(*this); + } + typename detail::shared_ptr_traits::reference operator* () const // never throws { BOOST_ASSERT(px != 0);