mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +00:00
AK: Mark smart pointer classes as [[nodiscard]]
This makes it an error to not do something with a returned smart pointer, which should help prevent mistakes. In cases where you do need to ignore the value, casting to void will placate the compiler. I did have to add comments to disable clang-format on a couple of lines, where it wanted to format the code like this: ```c++ private : NonnullRefPtr() = delete; ```
This commit is contained in:
parent
3ca2aee054
commit
5013a6480d
5 changed files with 8 additions and 5 deletions
|
@ -39,7 +39,7 @@ ALWAYS_INLINE void unref_if_not_null(T* ptr)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
class NonnullRefPtr {
|
||||
class [[nodiscard]] NonnullRefPtr {
|
||||
template<typename U, typename P>
|
||||
friend class RefPtr;
|
||||
template<typename U>
|
||||
|
@ -218,8 +218,11 @@ public:
|
|||
AK::swap(m_ptr, other.m_ptr);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
private:
|
||||
NonnullRefPtr() = delete;
|
||||
// clang-format on
|
||||
|
||||
ALWAYS_INLINE RETURNS_NONNULL T* as_nonnull_ptr() const
|
||||
{
|
||||
VERIFY(m_ptr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue