diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index 9197631405..482b628e08 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include "StdLib.h" +#include "Types.h" namespace AK { @@ -12,8 +12,17 @@ public: explicit OwnPtr(T* ptr) : m_ptr(ptr) { } OwnPtr(OwnPtr&& other) : m_ptr(other.leakPtr()) { } template OwnPtr(OwnPtr&& other) : m_ptr(static_cast(other.leakPtr())) { } - ~OwnPtr() { clear(); } OwnPtr(std::nullptr_t) { }; + ~OwnPtr() + { + clear(); +#ifdef SANITIZE_PTRS + if constexpr(sizeof(T*) == 8) + m_ptr = (T*)(0xe1e1e1e1e1e1e1e1); + else + m_ptr = (T*)(0xe1e1e1e1); +#endif + } OwnPtr& operator=(OwnPtr&& other) { @@ -84,7 +93,7 @@ private: template inline OwnPtr make(Args&&... args) { - return OwnPtr(new T(std::forward(args)...)); + return OwnPtr(new T(forward(args)...)); } } diff --git a/AK/RetainPtr.h b/AK/RetainPtr.h index 5bc6ba6287..c2fbd215d0 100644 --- a/AK/RetainPtr.h +++ b/AK/RetainPtr.h @@ -1,8 +1,6 @@ #pragma once -namespace std { -typedef decltype(nullptr) nullptr_t; -} +#include "Types.h" namespace AK { @@ -32,7 +30,16 @@ public: RetainPtr(AdoptTag, T& object) : m_ptr(&object) { } RetainPtr(RetainPtr&& other) : m_ptr(other.leakRef()) { } template RetainPtr(RetainPtr&& other) : m_ptr(static_cast(other.leakRef())) { } - ~RetainPtr() { clear(); } + ~RetainPtr() + { + clear(); +#ifdef SANITIZE_PTRS + if constexpr(sizeof(T*) == 8) + m_ptr = (T*)(0xe0e0e0e0e0e0e0e0); + else + m_ptr = (T*)(0xe0e0e0e0); +#endif + } RetainPtr(std::nullptr_t) { } RetainPtr& operator=(RetainPtr&& other) diff --git a/AK/StdLib.h b/AK/StdLib.h index 5c70559087..c4448ed423 100644 --- a/AK/StdLib.h +++ b/AK/StdLib.h @@ -30,9 +30,31 @@ T&& move(T& arg) return static_cast(arg); } +template +struct identity { + typedef T type; +}; +template +T&& forward(typename identity::type&& param) +{ + return static_cast::type&&>(param); +} + +template +T exchange(T& a, U&& b) +{ + T tmp = move(a); + a = move(b); + return tmp; +} + + } using AK::min; using AK::max; +using AK::move; +using AK::forward; +using AK::exchange; using AK::ceilDiv;