mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:57:45 +00:00
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
1 changed files with 8 additions and 4 deletions
|
@ -47,10 +47,10 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
operator int() const { return m_error; }
|
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; }
|
[[nodiscard]] bool is_success() const { return m_error == 0; }
|
||||||
bool is_error() const { return !is_success(); }
|
[[nodiscard]] bool is_error() const { return !is_success(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -115,18 +115,22 @@ public:
|
||||||
value().~T();
|
value().~T();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_error() const { return m_is_error; }
|
[[nodiscard]] bool is_error() const { return m_is_error; }
|
||||||
|
|
||||||
ALWAYS_INLINE KResult error() const
|
ALWAYS_INLINE KResult error() const
|
||||||
{
|
{
|
||||||
ASSERT(m_is_error);
|
ASSERT(m_is_error);
|
||||||
return m_error;
|
return m_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult result() const { return m_is_error ? KSuccess : m_error; }
|
KResult result() const { return m_is_error ? KSuccess : m_error; }
|
||||||
|
|
||||||
ALWAYS_INLINE T& value()
|
ALWAYS_INLINE T& value()
|
||||||
{
|
{
|
||||||
ASSERT(!m_is_error);
|
ASSERT(!m_is_error);
|
||||||
return *reinterpret_cast<T*>(&m_storage);
|
return *reinterpret_cast<T*>(&m_storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE const T& value() const
|
ALWAYS_INLINE const T& value() const
|
||||||
{
|
{
|
||||||
ASSERT(!m_is_error);
|
ASSERT(!m_is_error);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue