Kernel: Decorate KResult and KResultOr<T> methods with [[nodiscard]]
This would have found my error propagation bug.
This commit is contained in:
parent
fe64d97001
commit
34dd8edcb3
Notes:
sideshowbarker
2024-07-19 04:08:58 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/34dd8edcb3f Pull-request: https://github.com/SerenityOS/serenity/pull/3049
1 changed files with 8 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue