From 68e23bca3f732f69eb1521cc73cc6d346364b3cb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 7 Nov 2019 18:00:05 +0100 Subject: [PATCH] AK: Delete operator!() and operator bool() from the Nonnull pointers Since NonnullRefPtr and NonnullOwnPtr cannot be null, it is pointless to convert them to a bool, since it would always be true. This patch makes it an error to null-check one of these pointers. --- AK/NonnullOwnPtr.h | 3 +++ AK/NonnullRefPtr.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index efb3fef704..f1f07011a6 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -121,6 +121,9 @@ public: CALLABLE_WHEN(unconsumed) operator T*() { return m_ptr; } + operator bool() const = delete; + bool operator!() const = delete; + private: void clear() { diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 812457a01a..90ad50ca75 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -221,6 +221,9 @@ public: return *m_ptr; } + operator bool() const = delete; + bool operator!() const = delete; + private: NonnullRefPtr() = delete;