1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:17:44 +00:00

AK: Mark Optional getters as [[nodiscard]]

There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
This commit is contained in:
Brian Gianforcaro 2021-02-14 15:21:04 -08:00 committed by Andreas Kling
parent 8752a27519
commit 3356f438ca

View file

@ -124,20 +124,20 @@ public:
new (&m_storage) T(forward<Parameters>(parameters)...); new (&m_storage) T(forward<Parameters>(parameters)...);
} }
ALWAYS_INLINE bool has_value() const { return m_has_value; } [[nodiscard]] ALWAYS_INLINE bool has_value() const { return m_has_value; }
ALWAYS_INLINE T& value() [[nodiscard]] ALWAYS_INLINE T& value()
{ {
ASSERT(m_has_value); ASSERT(m_has_value);
return *reinterpret_cast<T*>(&m_storage); return *reinterpret_cast<T*>(&m_storage);
} }
ALWAYS_INLINE const T& value() const [[nodiscard]] ALWAYS_INLINE const T& value() const
{ {
return value_without_consume_state(); return value_without_consume_state();
} }
T release_value() [[nodiscard]] T release_value()
{ {
ASSERT(m_has_value); ASSERT(m_has_value);
T released_value = move(value()); T released_value = move(value());
@ -146,7 +146,7 @@ public:
return released_value; return released_value;
} }
ALWAYS_INLINE T value_or(const T& fallback) const [[nodiscard]] ALWAYS_INLINE T value_or(const T& fallback) const
{ {
if (m_has_value) if (m_has_value)
return value(); return value();