From ed3420dc10fab9d166ccab7bbe50e704f4b79064 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 4 Feb 2023 18:34:35 +0100 Subject: [PATCH] AK: Make WeakPtr::value() return NonnullRefPtr This API is only used by Jakt to implement weak reference unwrapping. By making it return a NonnullRefPtr, it can be assigned to anything that accepts a NonnullRefPtr, unlike the previous T* return type (since that can also be null). --- AK/WeakPtr.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/AK/WeakPtr.h b/AK/WeakPtr.h index bf4eabc863..9f74eb09c9 100644 --- a/AK/WeakPtr.h +++ b/AK/WeakPtr.h @@ -149,8 +149,11 @@ public: return nullptr; } - [[nodiscard]] T const* value() const { return unsafe_ptr(); } - [[nodiscard]] T* value() { return unsafe_ptr(); } + [[nodiscard]] NonnullRefPtr value() const + { + VERIFY(has_value()); + return *unsafe_ptr(); + } operator bool() const { return m_link ? !m_link->is_null() : false; }