mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
AK: Ensure we never use OwnPtr<> with RefCounted types
This commit is contained in:
parent
62d1ac63e8
commit
0466810638
Notes:
sideshowbarker
2024-07-19 05:42:21 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/04668106386 Pull-request: https://github.com/SerenityOS/serenity/pull/2547
@ -28,6 +28,7 @@
|
||||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/LogStream.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <AK/Types.h>
|
||||
@ -51,6 +52,7 @@ public:
|
||||
NonnullOwnPtr(AdoptTag, T& ptr)
|
||||
: m_ptr(&ptr)
|
||||
{
|
||||
static_assert(!is_ref_counted((const T*)nullptr), "Use RefPtr<> for RefCounted types");
|
||||
}
|
||||
NonnullOwnPtr(NonnullOwnPtr&& other)
|
||||
: m_ptr(other.leak_ptr())
|
||||
|
@ -27,16 +27,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
class OwnPtr {
|
||||
public:
|
||||
OwnPtr() {}
|
||||
OwnPtr() { }
|
||||
explicit OwnPtr(T* ptr)
|
||||
: m_ptr(ptr)
|
||||
{
|
||||
static_assert(!is_ref_counted((const T*)nullptr), "Use RefPtr<> for RefCounted types");
|
||||
}
|
||||
OwnPtr(OwnPtr&& other)
|
||||
: m_ptr(other.leak_ptr())
|
||||
|
@ -100,6 +100,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr bool is_ref_counted(const RefCountedBase*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static constexpr bool is_ref_counted(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::RefCounted;
|
||||
|
Loading…
Reference in New Issue
Block a user