From d5470467521c511c11345eb7351d8fca79d127a5 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 26 Jun 2020 13:12:58 +0200 Subject: [PATCH] Assert BorrowedPtr is not null when trying to dereference it. --- src/Memory/BorrowedPtr.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Memory/BorrowedPtr.hpp b/src/Memory/BorrowedPtr.hpp index ee8eefa..382138d 100644 --- a/src/Memory/BorrowedPtr.hpp +++ b/src/Memory/BorrowedPtr.hpp @@ -2,6 +2,7 @@ #define ARBUTILS_BORROWEDPTR_HPP #include +#include "../Assert.hpp" namespace ArbUt { /// A borrowed pointer is used to indicate a pointer that is not owned by an object, but instead borrowed from @@ -24,7 +25,10 @@ namespace ArbUt { return *this; } - inline T* operator->() const noexcept { return _raw; } + inline T* operator->() const noexcept { + AssertNotNull(_raw); + return _raw; + } inline T* GetRaw() const noexcept { return _raw; } inline bool operator==(const BorrowedPtr& rhs) const noexcept { return _raw == rhs._raw; } @@ -32,9 +36,7 @@ namespace ArbUt { [[nodiscard]] inline constexpr bool IsNull() const noexcept { return _raw == nullptr; } - inline BorrowedPtr Const() const noexcept { - return BorrowedPtr(_raw); - } + inline BorrowedPtr Const() const noexcept { return BorrowedPtr(_raw); } template inline BorrowedPtr As() const { auto cast = dynamic_cast(_raw);