AK: Ensure RefCounted types are never copied or moved

Before this, it has been possible to assign a RefCounted object to another
RefCounted object. Hilariosly (or sadly), that copied the refcount among
the other fields, meaning the target value ended up with a wrong refcount.

Ensure this never happens by disallowing copies and moves for RefCounted types.
This commit is contained in:
Sergey Bugaev 2020-06-12 16:46:47 +03:00 committed by Andreas Kling
parent 0ff3c1c34d
commit 3ff651323c
Notes: sideshowbarker 2024-07-19 05:42:07 +09:00

View file

@ -29,6 +29,7 @@
#include <AK/Assertions.h>
#include <AK/Atomic.h>
#include <AK/Checked.h>
#include <AK/Noncopyable.h>
#include <AK/Platform.h>
#include <AK/StdLibExtras.h>
@ -59,6 +60,8 @@ constexpr auto call_one_ref_left_if_present(...) -> FalseType
}
class RefCountedBase {
AK_MAKE_NONCOPYABLE(RefCountedBase)
AK_MAKE_NONMOVABLE(RefCountedBase)
public:
typedef unsigned int RefCountType;