mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 04:20:28 +00:00
AK: Stop allowing implicit downcast with OwnPtr and NonnullOwnPtr
Same issue here as we had with RefPtr and NonnullRefPtr. Since we can't make copies of an owning pointer, we don't get quite the same static_ptr_cast<T> here. Instead I've only added a new templated version of OwnPtr::release_nonnull() in this patch, to solve the only issue that popped up. I'm not sure what the best solution here is, but this works for now.
This commit is contained in:
parent
1d468ed6d3
commit
4f200def9c
Notes:
sideshowbarker
2024-07-19 07:54:21 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4f200def9c7
3 changed files with 12 additions and 5 deletions
|
@ -62,7 +62,7 @@ public:
|
|||
template<typename U>
|
||||
RETURN_TYPESTATE(unconsumed)
|
||||
NonnullOwnPtr(NonnullOwnPtr<U>&& other)
|
||||
: m_ptr(static_cast<T*>(other.leak_ptr()))
|
||||
: m_ptr(other.leak_ptr())
|
||||
{
|
||||
ASSERT(m_ptr);
|
||||
}
|
||||
|
|
11
AK/OwnPtr.h
11
AK/OwnPtr.h
|
@ -45,12 +45,12 @@ public:
|
|||
|
||||
template<typename U>
|
||||
OwnPtr(NonnullOwnPtr<U>&& other)
|
||||
: m_ptr(static_cast<T*>(other.leak_ptr()))
|
||||
: m_ptr(other.leak_ptr())
|
||||
{
|
||||
}
|
||||
template<typename U>
|
||||
OwnPtr(OwnPtr<U>&& other)
|
||||
: m_ptr(static_cast<T*>(other.leak_ptr()))
|
||||
: m_ptr(other.leak_ptr())
|
||||
{
|
||||
}
|
||||
OwnPtr(std::nullptr_t) {};
|
||||
|
@ -148,6 +148,13 @@ public:
|
|||
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, *leak_ptr());
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
NonnullOwnPtr<U> release_nonnull()
|
||||
{
|
||||
ASSERT(m_ptr);
|
||||
return NonnullOwnPtr<U>(NonnullOwnPtr<U>::Adopt, static_cast<U&>(*leak_ptr()));
|
||||
}
|
||||
|
||||
T* ptr() { return m_ptr; }
|
||||
const T* ptr() const { return m_ptr; }
|
||||
|
||||
|
|
|
@ -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<MessageType>();
|
||||
}
|
||||
}
|
||||
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<MessageType>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue