mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Explicitly delete NonnullRefPtr::operator=(RefPtr).
This gives us much better error messages when you try to use them. Without this change, it would complain about the absence of functions named ref() and deref() on RefPtr itself. With it, we instead get a "hey, this function is deleted" error. Change operator=(T&) to operator=T(const T&) also, to keep assigning a const T& to a NonnullRefPtr working.
This commit is contained in:
parent
6db879ee66
commit
06f82901b7
Notes:
sideshowbarker
2024-07-19 12:56:44 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/06f82901b7c
1 changed files with 11 additions and 2 deletions
|
@ -8,6 +8,8 @@ namespace AK {
|
|||
|
||||
template<typename T>
|
||||
class OwnPtr;
|
||||
template<typename T>
|
||||
class RefPtr;
|
||||
|
||||
template<typename T>
|
||||
inline void ref_if_not_null(T* ptr)
|
||||
|
@ -89,6 +91,13 @@ public:
|
|||
template<typename U>
|
||||
NonnullRefPtr& operator=(const OwnPtr<U>&) = delete;
|
||||
|
||||
template<typename U>
|
||||
NonnullRefPtr(const RefPtr<U>&) = delete;
|
||||
template<typename U>
|
||||
NonnullRefPtr& operator=(const RefPtr<U>&) = delete;
|
||||
NonnullRefPtr(const RefPtr<T>&) = delete;
|
||||
NonnullRefPtr& operator=(const RefPtr<T>&) = delete;
|
||||
|
||||
NonnullRefPtr& operator=(const NonnullRefPtr& other)
|
||||
{
|
||||
if (m_ptr != other.m_ptr) {
|
||||
|
@ -129,11 +138,11 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
NonnullRefPtr& operator=(T& object)
|
||||
NonnullRefPtr& operator=(const T& object)
|
||||
{
|
||||
if (m_ptr != &object) {
|
||||
deref_if_not_null(m_ptr);
|
||||
m_ptr = &object;
|
||||
m_ptr = const_cast<T*>(&object);
|
||||
m_ptr->ref();
|
||||
}
|
||||
return *this;
|
||||
|
|
Loading…
Reference in a new issue