Improve assignment operators for IntrusivePtr

Fixes Coverity finding 1367523 (Missing move assignment operator).
This commit is contained in:
Dominik Charousset 2021-06-06 15:34:24 +02:00
parent 9fbbcaad8f
commit 2f19c89189

View file

@ -137,12 +137,29 @@ public:
return std::exchange(ptr_, nullptr); return std::exchange(ptr_, nullptr);
} }
IntrusivePtr& operator=(IntrusivePtr other) noexcept IntrusivePtr& operator=(const IntrusivePtr& other) noexcept
{
IntrusivePtr tmp{other};
swap(tmp);
return *this;
}
IntrusivePtr& operator=(IntrusivePtr&& other) noexcept
{ {
swap(other); swap(other);
return *this; return *this;
} }
IntrusivePtr& operator=(std::nullptr_t) noexcept
{
if ( ptr_ )
{
Unref(ptr_);
ptr_ = nullptr;
}
return *this;
}
pointer get() const noexcept pointer get() const noexcept
{ {
return ptr_; return ptr_;