mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Delete bad pointer assignment operators and constructors.
We shouldn't allow constructing e.g an OwnPtr from a RefPtr, and similar conversions. Instead just delete those functions so the compiler whines loudly if you try to use them. This patch also deletes constructing OwnPtr from a WeakPtr, even though that *may* be a valid thing to do, it's sufficiently weird that we can make the client jump through some hoops if he really wants it. :^)
This commit is contained in:
parent
01998a10e3
commit
25e3d46502
Notes:
sideshowbarker
2024-07-19 13:19:13 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/25e3d465025
3 changed files with 36 additions and 0 deletions
|
@ -18,6 +18,9 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
class OwnPtr;
|
||||
|
||||
template<typename T>
|
||||
inline void ref_if_not_null(T* ptr)
|
||||
{
|
||||
|
@ -93,6 +96,11 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
NonnullRefPtr(const OwnPtr<U>&) = delete;
|
||||
template<typename U>
|
||||
NonnullRefPtr& operator=(const OwnPtr<U>&) = delete;
|
||||
|
||||
NonnullRefPtr& operator=(const NonnullRefPtr& other)
|
||||
{
|
||||
if (m_ptr != other.m_ptr) {
|
||||
|
|
20
AK/OwnPtr.h
20
AK/OwnPtr.h
|
@ -7,6 +7,13 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
class RefPtr;
|
||||
template<typename T>
|
||||
class NonnullRefPtr;
|
||||
template<typename T>
|
||||
class WeakPtr;
|
||||
|
||||
template<typename T>
|
||||
class OwnPtr {
|
||||
public:
|
||||
|
@ -36,6 +43,19 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
OwnPtr(const RefPtr<U>&) = delete;
|
||||
template<typename U>
|
||||
OwnPtr(const NonnullRefPtr<U>&) = delete;
|
||||
template<typename U>
|
||||
OwnPtr(const WeakPtr<U>&) = delete;
|
||||
template<typename U>
|
||||
OwnPtr& operator=(const RefPtr<U>&) = delete;
|
||||
template<typename U>
|
||||
OwnPtr& operator=(const NonnullRefPtr<U>&) = delete;
|
||||
template<typename U>
|
||||
OwnPtr& operator=(const WeakPtr<U>&) = delete;
|
||||
|
||||
OwnPtr& operator=(OwnPtr&& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
class OwnPtr;
|
||||
|
||||
template<typename T>
|
||||
class RefPtr {
|
||||
public:
|
||||
|
@ -86,6 +89,11 @@ public:
|
|||
}
|
||||
RefPtr(std::nullptr_t) {}
|
||||
|
||||
template<typename U>
|
||||
RefPtr(const OwnPtr<U>&) = delete;
|
||||
template<typename U>
|
||||
RefPtr& operator=(const OwnPtr<U>&) = delete;
|
||||
|
||||
RefPtr& operator=(RefPtr&& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
|
|
Loading…
Reference in a new issue