Stricter tests; associated bug fixes. ;-)

[SVN r16369]
This commit is contained in:
Peter Dimov
2002-11-22 13:49:54 +00:00
parent 66a8e8b3c1
commit 8d6517484c
3 changed files with 18 additions and 4 deletions

View File

@@ -140,8 +140,10 @@ public:
#endif
template<class Y>
explicit shared_ptr(weak_ptr<Y> const & r): px(r.px), pn(r.pn) // may throw
explicit shared_ptr(weak_ptr<Y> const & r): pn(r.pn) // may throw
{
// it is now safe to copy r.px, as pn(r.pn) did not throw
px = r.px;
}
template<class Y>
@@ -166,7 +168,7 @@ public:
template<class Y>
shared_ptr(shared_ptr<Y> const & r, detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
{
if (px == 0)
if(px == 0)
{
boost::throw_exception(std::bad_cast());
}

View File

@@ -16,6 +16,8 @@
#include <boost/shared_ptr.hpp>
#include <cstring> // for std::memcpy
#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
# pragma warning(push)
# pragma warning(disable:4284) // odd return type for operator->
@@ -42,8 +44,11 @@ public:
// generated copy constructor, assignment, destructor are fine
template<class Y>
weak_ptr(weak_ptr<Y> const & r): px(r.px), pn(r.pn) // never throws
weak_ptr(weak_ptr<Y> const & r): pn(r.pn) // never throws
{
// r.px may be an invalid pointer value
using namespace std;
memcpy(&this->px, &r.px, sizeof(r.px));
}
template<class Y>

View File

@@ -99,7 +99,9 @@ private:
long X::instances = 0;
struct Y: public A, public X
// virtual inheritance stresses the implementation
struct Y: public A, public virtual X
{
static long instances;
@@ -771,6 +773,11 @@ void weak_ptr_constructor()
catch(boost::bad_weak_ptr)
{
}
{
boost::weak_ptr<Y> wp2(wp);
boost::weak_ptr<X> wp3(wp);
}
}
void auto_ptr_constructor()