summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2020-08-08 12:29:09 -0700
committerAndreas Kling <kling@serenityos.org>2020-08-09 00:13:39 +0200
commit34dd8edcb3f9b7532b22ab6d41cd9623a791deb6 (patch)
tree53e81df1977e216f401d5f082f2d0caaa83356ae
parentfe64d97001af19cdd08afc5674f0755d227af0dc (diff)
downloadserenity-34dd8edcb3f9b7532b22ab6d41cd9623a791deb6.zip
Kernel: Decorate KResult and KResultOr<T> methods with [[nodiscard]]
This would have found my error propagation bug.
-rw-r--r--Kernel/KResult.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/Kernel/KResult.h b/Kernel/KResult.h
index 168b2825ce..cb457b09f1 100644
--- a/Kernel/KResult.h
+++ b/Kernel/KResult.h
@@ -47,10 +47,10 @@ public:
{
}
operator int() const { return m_error; }
- int error() const { return m_error; }
+ [[nodiscard]] int error() const { return m_error; }
- bool is_success() const { return m_error == 0; }
- bool is_error() const { return !is_success(); }
+ [[nodiscard]] bool is_success() const { return m_error == 0; }
+ [[nodiscard]] bool is_error() const { return !is_success(); }
private:
template<typename T>
@@ -115,18 +115,22 @@ public:
value().~T();
}
- bool is_error() const { return m_is_error; }
+ [[nodiscard]] bool is_error() const { return m_is_error; }
+
ALWAYS_INLINE KResult error() const
{
ASSERT(m_is_error);
return m_error;
}
+
KResult result() const { return m_is_error ? KSuccess : m_error; }
+
ALWAYS_INLINE T& value()
{
ASSERT(!m_is_error);
return *reinterpret_cast<T*>(&m_storage);
}
+
ALWAYS_INLINE const T& value() const
{
ASSERT(!m_is_error);