1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

AK: Annotate WeakPtr functions as [[nodiscard]]

This commit is contained in:
Brian Gianforcaro 2021-04-11 01:32:23 -07:00 committed by Andreas Kling
parent 56ab0da6a4
commit 23454cab46

View file

@ -143,7 +143,7 @@ public:
return *this; return *this;
} }
RefPtr<T> strong_ref() const [[nodiscard]] RefPtr<T> strong_ref() const
{ {
// This only works with RefCounted objects, but it is the only // This only works with RefCounted objects, but it is the only
// safe way to get a strong reference from a WeakPtr. Any code // safe way to get a strong reference from a WeakPtr. Any code
@ -169,7 +169,7 @@ public:
operator T*() { return unsafe_ptr(); } operator T*() { return unsafe_ptr(); }
#endif #endif
T* unsafe_ptr() const [[nodiscard]] T* unsafe_ptr() const
{ {
T* ptr = nullptr; T* ptr = nullptr;
m_link.do_while_locked([&](WeakLink* link) { m_link.do_while_locked([&](WeakLink* link) {
@ -181,10 +181,10 @@ public:
operator bool() const { return m_link ? !m_link->is_null() : false; } operator bool() const { return m_link ? !m_link->is_null() : false; }
bool is_null() const { return !m_link || m_link->is_null(); } [[nodiscard]] bool is_null() const { return !m_link || m_link->is_null(); }
void clear() { m_link = nullptr; } void clear() { m_link = nullptr; }
RefPtr<WeakLink> take_link() { return move(m_link); } [[nodiscard]] RefPtr<WeakLink> take_link() { return move(m_link); }
private: private:
WeakPtr(const RefPtr<WeakLink>& link) WeakPtr(const RefPtr<WeakLink>& link)