mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03: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
Notes:
sideshowbarker
2024-07-17 23:08:34 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/5013a6480d9 Pull-request: https://github.com/SerenityOS/serenity/pull/11151
@ -25,7 +25,7 @@ template<typename T>
|
|||||||
class WeakPtr;
|
class WeakPtr;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class NonnullOwnPtr {
|
class [[nodiscard]] NonnullOwnPtr {
|
||||||
public:
|
public:
|
||||||
using ElementType = T;
|
using ElementType = T;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ ALWAYS_INLINE void unref_if_not_null(T* ptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class NonnullRefPtr {
|
class [[nodiscard]] NonnullRefPtr {
|
||||||
template<typename U, typename P>
|
template<typename U, typename P>
|
||||||
friend class RefPtr;
|
friend class RefPtr;
|
||||||
template<typename U>
|
template<typename U>
|
||||||
@ -218,8 +218,11 @@ public:
|
|||||||
AK::swap(m_ptr, other.m_ptr);
|
AK::swap(m_ptr, other.m_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
private:
|
private:
|
||||||
NonnullRefPtr() = delete;
|
NonnullRefPtr() = delete;
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
ALWAYS_INLINE RETURNS_NONNULL T* as_nonnull_ptr() const
|
ALWAYS_INLINE RETURNS_NONNULL T* as_nonnull_ptr() const
|
||||||
{
|
{
|
||||||
VERIFY(m_ptr);
|
VERIFY(m_ptr);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class OwnPtr {
|
class [[nodiscard]] OwnPtr {
|
||||||
public:
|
public:
|
||||||
OwnPtr() = default;
|
OwnPtr() = default;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ template<typename T>
|
|||||||
class OwnPtr;
|
class OwnPtr;
|
||||||
|
|
||||||
template<typename T, typename PtrTraits>
|
template<typename T, typename PtrTraits>
|
||||||
class RefPtr {
|
class [[nodiscard]] RefPtr {
|
||||||
template<typename U, typename P>
|
template<typename U, typename P>
|
||||||
friend class RefPtr;
|
friend class RefPtr;
|
||||||
template<typename U>
|
template<typename U>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class WeakPtr {
|
class [[nodiscard]] WeakPtr {
|
||||||
template<typename U>
|
template<typename U>
|
||||||
friend class Weakable;
|
friend class Weakable;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user