From 3fb404961240eed6a3d97eaa0dcdda71241d098f Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 29 Aug 2024 16:13:30 +0200 Subject: [PATCH] Prevent accidentally copy/move of refcounted objects --- irr/include/IReferenceCounted.h | 4 ++++ src/util/pointer.h | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/irr/include/IReferenceCounted.h b/irr/include/IReferenceCounted.h index 6f85bb904..e1000d389 100644 --- a/irr/include/IReferenceCounted.h +++ b/irr/include/IReferenceCounted.h @@ -51,6 +51,10 @@ public: { } + // Reference counted objects can be neither copied nor moved. + IReferenceCounted(const IReferenceCounted &) = delete; + IReferenceCounted &operator=(const IReferenceCounted &) = delete; + //! Grabs the object. Increments the reference counter by one. /** Someone who calls grab() to an object, should later also call drop() to it. If an object never gets as much drop() as diff --git a/src/util/pointer.h b/src/util/pointer.h index 528897a1c..b7fad4fe1 100644 --- a/src/util/pointer.h +++ b/src/util/pointer.h @@ -273,9 +273,7 @@ public: void grab() noexcept { ++m_refcount; } void drop() noexcept { if (--m_refcount == 0) delete this; } - // Preserve own reference count. - IntrusiveReferenceCounted(const IntrusiveReferenceCounted &) {} - IntrusiveReferenceCounted &operator=(const IntrusiveReferenceCounted &) { return *this; } + DISABLE_CLASS_COPY(IntrusiveReferenceCounted) private: u32 m_refcount = 1; };