diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index c34b09de2fd..ddf2c6e50d7 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -62,7 +62,7 @@ public: template RETURN_TYPESTATE(unconsumed) NonnullOwnPtr(NonnullOwnPtr&& other) - : m_ptr(static_cast(other.leak_ptr())) + : m_ptr(other.leak_ptr()) { ASSERT(m_ptr); } diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index b975abd8739..ed351be0600 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -45,12 +45,12 @@ public: template OwnPtr(NonnullOwnPtr&& other) - : m_ptr(static_cast(other.leak_ptr())) + : m_ptr(other.leak_ptr()) { } template OwnPtr(OwnPtr&& other) - : m_ptr(static_cast(other.leak_ptr())) + : m_ptr(other.leak_ptr()) { } OwnPtr(std::nullptr_t) {}; @@ -148,6 +148,13 @@ public: return NonnullOwnPtr(NonnullOwnPtr::Adopt, *leak_ptr()); } + template + NonnullOwnPtr release_nonnull() + { + ASSERT(m_ptr); + return NonnullOwnPtr(NonnullOwnPtr::Adopt, static_cast(*leak_ptr())); + } + T* ptr() { return m_ptr; } const T* ptr() const { return m_ptr; } diff --git a/Libraries/LibIPC/ServerConnection.h b/Libraries/LibIPC/ServerConnection.h index bd8dfad71bd..949a0787442 100644 --- a/Libraries/LibIPC/ServerConnection.h +++ b/Libraries/LibIPC/ServerConnection.h @@ -93,7 +93,7 @@ public: if (m_unprocessed_messages[i]->message_id() == MessageType::static_message_id()) { auto message = move(m_unprocessed_messages[i]); m_unprocessed_messages.remove(i); - return message; + return message.template release_nonnull(); } } for (;;) { @@ -112,7 +112,7 @@ public: if (m_unprocessed_messages[i]->message_id() == MessageType::static_message_id()) { auto message = move(m_unprocessed_messages[i]); m_unprocessed_messages.remove(i); - return message; + return message.template release_nonnull(); } } }