From b8f95225f752900471dedacbe9b71fc0523393d9 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 27 Jun 2018 13:36:30 -0400 Subject: fix bugs in ref.h --- include/salticidae/ref.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'include/salticidae') diff --git a/include/salticidae/ref.h b/include/salticidae/ref.h index 83fd00b..001fd51 100644 --- a/include/salticidae/ref.h +++ b/include/salticidae/ref.h @@ -79,6 +79,7 @@ template class RcObjBase; template class WeakObjBase { + T *obj; R *ctl; void release() { if (ctl) ctl->release_weak(); } public: @@ -87,16 +88,19 @@ class WeakObjBase { WeakObjBase(): ctl(nullptr) {} WeakObjBase &operator=(const WeakObjBase &other) { release(); + obj = other.obj; if ((ctl = other.ctl)) ctl->add_weak(); return *this; } - WeakObjBase(const WeakObjBase &other): ctl(other.ctl) { + WeakObjBase(const WeakObjBase &other): + obj(other.obj), ctl(other.ctl) { if (ctl) ctl->add_weak(); } - WeakObjBase(WeakObjBase &&other): ctl(other.ctl) { + WeakObjBase(WeakObjBase &&other): + obj(other.obj), ctl(other.ctl) { other.ctl = nullptr; } @@ -132,11 +136,6 @@ class RcObjBase { return *this; } - RcObjBase(const RcObjBase &other): - obj(other.obj), ctl(other.ctl) { - if (ctl) ctl->add_ref(); - } - template RcObjBase(const RcObjBase &other): obj(other.obj), ctl(other.ctl) { @@ -178,7 +177,7 @@ RcObjBase static_pointer_cast(const RcObjBase &other) { template inline WeakObjBase::WeakObjBase(const RcObjBase &other): - ctl(other.ctl) { + obj(other.obj), ctl(other.ctl) { if (ctl) ctl->add_weak(); } -- cgit v1.2.3