diff options
author | Adam <Adam@anope.org> | 2012-05-17 02:03:22 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-05-17 02:03:22 -0400 |
commit | a883362c149770873c52fa017bb9a1678e737410 (patch) | |
tree | 93ad3b672615c0c56b2b705ce9ca105e07071c5e /include | |
parent | ef88385d850822d5b237b03abdce3f6c659756f4 (diff) |
Fixed not always calling operator bool() in dynamic_reference, which would mess up service references and do weird things
Diffstat (limited to 'include')
-rw-r--r-- | include/base.h | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/include/base.h b/include/base.h index cc0e84bf9..9ea0dc630 100644 --- a/include/base.h +++ b/include/base.h @@ -53,18 +53,20 @@ class dynamic_reference : public dynamic_reference_base dynamic_reference(const dynamic_reference<T> &other) : dynamic_reference_base(other), ref(other.ref) { - if (*this) + if (operator bool()) ref->AddReference(this); } virtual ~dynamic_reference() { - if (*this) - { + if (operator bool()) ref->DelReference(this); - } } + /* We explicitly call operator bool here in several places to prevent other + * operators, such operator T*, from being called instead, which will mess + * with any class inheriting from this that overloads this operator. + */ virtual operator bool() { if (!this->invalid) @@ -72,31 +74,36 @@ class dynamic_reference : public dynamic_reference_base return false; } - virtual inline operator T*() const + inline operator T*() { - if (!this->invalid) + if (operator bool()) return this->ref; return NULL; } - virtual inline T* operator->() + inline T* operator->() { - if (!this->invalid) + if (operator bool()) return this->ref; return NULL; } - virtual inline void operator=(T *newref) + inline void operator=(T *newref) { - if (*this) + if (operator bool()) this->ref->DelReference(this); this->ref = newref; this->invalid = false; - if (*this) + if (operator bool()) this->ref->AddReference(this); } - virtual inline bool operator==(const dynamic_reference<T> &other) const + inline bool operator<(const dynamic_reference<T> &other) const + { + return this < &other; + } + + inline bool operator==(const dynamic_reference<T> &other) { if (!this->invalid) return this->ref == other; |