From 06f82901b7c8e52562566e958740b24217463ea9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 2 Aug 2019 11:51:28 +0200 Subject: [PATCH] AK: Explicitly delete NonnullRefPtr::operator=(RefPtr). This gives us much better error messages when you try to use them. Without this change, it would complain about the absence of functions named ref() and deref() on RefPtr itself. With it, we instead get a "hey, this function is deleted" error. Change operator=(T&) to operator=T(const T&) also, to keep assigning a const T& to a NonnullRefPtr working. --- AK/NonnullRefPtr.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 56772dea4c..fcb4bc245a 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -8,6 +8,8 @@ namespace AK { template class OwnPtr; +template +class RefPtr; template inline void ref_if_not_null(T* ptr) @@ -89,6 +91,13 @@ public: template NonnullRefPtr& operator=(const OwnPtr&) = delete; + template + NonnullRefPtr(const RefPtr&) = delete; + template + NonnullRefPtr& operator=(const RefPtr&) = delete; + NonnullRefPtr(const RefPtr&) = delete; + NonnullRefPtr& operator=(const RefPtr&) = delete; + NonnullRefPtr& operator=(const NonnullRefPtr& other) { if (m_ptr != other.m_ptr) { @@ -129,11 +138,11 @@ public: return *this; } - NonnullRefPtr& operator=(T& object) + NonnullRefPtr& operator=(const T& object) { if (m_ptr != &object) { deref_if_not_null(m_ptr); - m_ptr = &object; + m_ptr = const_cast(&object); m_ptr->ref(); } return *this;