From 3356f438caa17883d2b008d44013939abbc5033f Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 14 Feb 2021 15:21:04 -0800 Subject: [PATCH] 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. --- AK/Optional.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AK/Optional.h b/AK/Optional.h index e36f5a0a7e..057c16fcf4 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -124,20 +124,20 @@ public: new (&m_storage) T(forward(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); return *reinterpret_cast(&m_storage); } - ALWAYS_INLINE const T& value() const + [[nodiscard]] ALWAYS_INLINE const T& value() const { return value_without_consume_state(); } - T release_value() + [[nodiscard]] T release_value() { ASSERT(m_has_value); T released_value = move(value()); @@ -146,7 +146,7 @@ public: 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) return value();