diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-11 16:43:20 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-11 16:50:30 +0200 |
commit | 25e3d465025a377d5ad8528d7cb23ec3bdc9f285 (patch) | |
tree | 59c0ba9d7b418103e532445a5c35b401bdc683e6 /AK | |
parent | 01998a10e3c06e5a352b055e8854632379ed0a55 (diff) | |
download | serenity-25e3d465025a377d5ad8528d7cb23ec3bdc9f285.zip |
AK: Delete bad pointer assignment operators and constructors.
We shouldn't allow constructing e.g an OwnPtr from a RefPtr, and similar
conversions. Instead just delete those functions so the compiler whines
loudly if you try to use them.
This patch also deletes constructing OwnPtr from a WeakPtr, even though
that *may* be a valid thing to do, it's sufficiently weird that we can
make the client jump through some hoops if he really wants it. :^)
Diffstat (limited to 'AK')
-rw-r--r-- | AK/NonnullRefPtr.h | 8 | ||||
-rw-r--r-- | AK/OwnPtr.h | 20 | ||||
-rw-r--r-- | AK/RefPtr.h | 8 |
3 files changed, 36 insertions, 0 deletions
diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 53ab7aeccd..a055ccc681 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -19,6 +19,9 @@ namespace AK { template<typename T> +class OwnPtr; + +template<typename T> inline void ref_if_not_null(T* ptr) { if (ptr) @@ -93,6 +96,11 @@ public: #endif } + template<typename U> + NonnullRefPtr(const OwnPtr<U>&) = delete; + template<typename U> + NonnullRefPtr& operator=(const OwnPtr<U>&) = delete; + NonnullRefPtr& operator=(const NonnullRefPtr& other) { if (m_ptr != other.m_ptr) { diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index a10cc5bdb0..ba93fd63b3 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -8,6 +8,13 @@ namespace AK { template<typename T> +class RefPtr; +template<typename T> +class NonnullRefPtr; +template<typename T> +class WeakPtr; + +template<typename T> class OwnPtr { public: OwnPtr() {} @@ -36,6 +43,19 @@ public: #endif } + template<typename U> + OwnPtr(const RefPtr<U>&) = delete; + template<typename U> + OwnPtr(const NonnullRefPtr<U>&) = delete; + template<typename U> + OwnPtr(const WeakPtr<U>&) = delete; + template<typename U> + OwnPtr& operator=(const RefPtr<U>&) = delete; + template<typename U> + OwnPtr& operator=(const NonnullRefPtr<U>&) = delete; + template<typename U> + OwnPtr& operator=(const WeakPtr<U>&) = delete; + OwnPtr& operator=(OwnPtr&& other) { if (this != &other) { diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 349fb1de1c..99ebca89b9 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -7,6 +7,9 @@ namespace AK { template<typename T> +class OwnPtr; + +template<typename T> class RefPtr { public: enum AdoptTag { @@ -86,6 +89,11 @@ public: } RefPtr(std::nullptr_t) {} + template<typename U> + RefPtr(const OwnPtr<U>&) = delete; + template<typename U> + RefPtr& operator=(const OwnPtr<U>&) = delete; + RefPtr& operator=(RefPtr&& other) { if (this != &other) { |