Commit 6bc4c7a6 authored by Harris Hancock's avatar Harris Hancock

Disallow copy construction/assignment of (Atomic)Refcounted classes

If a multiply-inherited subclass of kj::Refcounted is move-assigned from an object of its other parent class's type, the reference count would get zeroed out. This change makes such mistakes a compile error.
parent 291f1d86
...@@ -67,7 +67,9 @@ class Refcounted: private Disposer { ...@@ -67,7 +67,9 @@ class Refcounted: private Disposer {
// Own<T> could also be nice. // Own<T> could also be nice.
public: public:
Refcounted() = default;
virtual ~Refcounted() noexcept(false); virtual ~Refcounted() noexcept(false);
KJ_DISALLOW_COPY(Refcounted);
inline bool isShared() const { return refcount > 1; } inline bool isShared() const { return refcount > 1; }
// Check if there are multiple references to this object. This is sometimes useful for deciding // Check if there are multiple references to this object. This is sometimes useful for deciding
...@@ -127,7 +129,9 @@ Own<T> Refcounted::addRefInternal(T* object) { ...@@ -127,7 +129,9 @@ Own<T> Refcounted::addRefInternal(T* object) {
class AtomicRefcounted: private kj::Disposer { class AtomicRefcounted: private kj::Disposer {
public: public:
AtomicRefcounted() = default;
virtual ~AtomicRefcounted() noexcept(false); virtual ~AtomicRefcounted() noexcept(false);
KJ_DISALLOW_COPY(AtomicRefcounted);
inline bool isShared() const { inline bool isShared() const {
#if _MSC_VER #if _MSC_VER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment