AK+LibJS: Add [[nodiscard]] to operator* in common types

The order of precedence with the `*` operator sometimes makes it a bit
harder to detect whether or not the result is actually used. Let's fail
compilation if anyone tries to discard the result.
This commit is contained in:
Jelle Raaijmakers 2024-10-24 22:36:28 +02:00 committed by Andreas Kling
parent 5ab07f277c
commit 0de403fede
Notes: github-actions[bot] 2024-10-25 07:16:17 +00:00
8 changed files with 11 additions and 11 deletions

View file

@ -76,12 +76,12 @@ public:
return SimpleIterator { *m_container, m_index + 1 };
}
ALWAYS_INLINE constexpr ValueType const& operator*() const
[[nodiscard]] ALWAYS_INLINE constexpr ValueType const& operator*() const
requires(IsConst<ValueType>)
{
return (*m_container)[m_index];
}
ALWAYS_INLINE constexpr ValueType& operator*() const
[[nodiscard]] ALWAYS_INLINE constexpr ValueType& operator*() const
requires(!IsConst<ValueType>)
{
return (*m_container)[m_index];

View file

@ -101,7 +101,7 @@ public:
ALWAYS_INLINE RETURNS_NONNULL T* operator->() const { return ptr(); }
ALWAYS_INLINE T& operator*() const { return *ptr(); }
[[nodiscard]] ALWAYS_INLINE T& operator*() const { return *ptr(); }
ALWAYS_INLINE RETURNS_NONNULL operator T*() const { return ptr(); }

View file

@ -168,7 +168,7 @@ public:
return as_nonnull_ptr();
}
ALWAYS_INLINE T& operator*() const
[[nodiscard]] ALWAYS_INLINE T& operator*() const
{
return *as_nonnull_ptr();
}

View file

@ -274,8 +274,8 @@ public:
return TRY(callback());
}
ALWAYS_INLINE T const& operator*() const { return value(); }
ALWAYS_INLINE T& operator*() { return value(); }
[[nodiscard]] ALWAYS_INLINE T const& operator*() const { return value(); }
[[nodiscard]] ALWAYS_INLINE T& operator*() { return value(); }
ALWAYS_INLINE T const* operator->() const { return &value(); }
ALWAYS_INLINE T* operator->() { return &value(); }

View file

@ -140,7 +140,7 @@ public:
return m_ptr;
}
T& operator*() const
[[nodiscard]] T& operator*() const
{
VERIFY(m_ptr);
return *m_ptr;

View file

@ -244,7 +244,7 @@ public:
return as_nonnull_ptr();
}
ALWAYS_INLINE T& operator*() const
[[nodiscard]] ALWAYS_INLINE T& operator*() const
{
return *as_nonnull_ptr();
}

View file

@ -62,7 +62,7 @@ public:
RETURNS_NONNULL T* operator->() const { return m_ptr; }
T& operator*() const { return *m_ptr; }
[[nodiscard]] T& operator*() const { return *m_ptr; }
RETURNS_NONNULL T* ptr() const { return m_ptr; }
@ -169,7 +169,7 @@ public:
return m_ptr;
}
T& operator*() const
[[nodiscard]] T& operator*() const
{
ASSERT(m_ptr);
return *m_ptr;

View file

@ -96,7 +96,7 @@ public:
return cell();
}
T& operator*() const
[[nodiscard]] T& operator*() const
{
return *cell();
}