diff options
author | Andreas Kling <kling@serenityos.org> | 2023-02-21 09:22:18 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-21 09:22:18 +0100 |
commit | 7ac7a73758f7060bc19b48b973a496bd8486dbae (patch) | |
tree | 5e5762ea844e8b0cc3a33e93c464042145c88e9d /AK/RefPtr.h | |
parent | f6eb155167e8bca9fba9cddb88b39ab7b049ff5d (diff) | |
download | serenity-7ac7a73758f7060bc19b48b973a496bd8486dbae.zip |
Revert "AK: Disallow constness laundering in RefPtr and NonnullRefPtr"
This reverts commit 3c7a0ef1ac279c99bc4ee72085278ea70c210889.
This broke Jakt, which will need some adjustments to its code generation
before we can commit to being this strict.
Diffstat (limited to 'AK/RefPtr.h')
-rw-r--r-- | AK/RefPtr.h | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 661a345131..1c28a07d9a 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -35,14 +35,14 @@ public: }; RefPtr() = default; - RefPtr(T* ptr) - : m_ptr(ptr) + RefPtr(T const* ptr) + : m_ptr(const_cast<T*>(ptr)) { ref_if_not_null(m_ptr); } - RefPtr(T& object) - : m_ptr(&object) + RefPtr(T const& object) + : m_ptr(const_cast<T*>(&object)) { m_ptr->ref(); } @@ -58,7 +58,7 @@ public: } ALWAYS_INLINE RefPtr(NonnullRefPtr<T> const& other) - : m_ptr(other.ptr()) + : m_ptr(const_cast<T*>(other.ptr())) { m_ptr->ref(); } @@ -66,7 +66,7 @@ public: template<typename U> ALWAYS_INLINE RefPtr(NonnullRefPtr<U> const& other) requires(IsConvertible<U*, T*>) - : m_ptr(static_cast<T*>(other.ptr())) + : m_ptr(const_cast<T*>(static_cast<T const*>(other.ptr()))) { m_ptr->ref(); } @@ -94,7 +94,7 @@ public: template<typename U> RefPtr(RefPtr<U> const& other) requires(IsConvertible<U*, T*>) - : m_ptr(static_cast<T*>(other.ptr())) + : m_ptr(const_cast<T*>(static_cast<T const*>(other.ptr()))) { ref_if_not_null(m_ptr); } @@ -181,14 +181,14 @@ public: return *this; } - ALWAYS_INLINE RefPtr& operator=(T* ptr) + ALWAYS_INLINE RefPtr& operator=(T const* ptr) { RefPtr tmp { ptr }; swap(tmp); return *this; } - ALWAYS_INLINE RefPtr& operator=(T& object) + ALWAYS_INLINE RefPtr& operator=(T const& object) { RefPtr tmp { object }; swap(tmp); @@ -304,13 +304,13 @@ struct Traits<RefPtr<T>> : public GenericTraits<RefPtr<T>> { template<typename T, typename U> inline NonnullRefPtr<T> static_ptr_cast(NonnullRefPtr<U> const& ptr) { - return NonnullRefPtr<T>(static_cast<T&>(*ptr)); + return NonnullRefPtr<T>(static_cast<T const&>(*ptr)); } template<typename T, typename U> inline RefPtr<T> static_ptr_cast(RefPtr<U> const& ptr) { - return RefPtr<T>(static_cast<T*>(ptr.ptr())); + return RefPtr<T>(static_cast<T const*>(ptr.ptr())); } template<typename T, typename U> |