From 2f19c89189420057d7dc8066c1abde250dddb2b8 Mon Sep 17 00:00:00 2001 From: Dominik Charousset Date: Sun, 6 Jun 2021 15:34:24 +0200 Subject: [PATCH] Improve assignment operators for IntrusivePtr Fixes Coverity finding 1367523 (Missing move assignment operator). --- src/IntrusivePtr.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/IntrusivePtr.h b/src/IntrusivePtr.h index 7ad37031c8..cb09e9c9f8 100644 --- a/src/IntrusivePtr.h +++ b/src/IntrusivePtr.h @@ -137,12 +137,29 @@ public: 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); return *this; } + IntrusivePtr& operator=(std::nullptr_t) noexcept + { + if ( ptr_ ) + { + Unref(ptr_); + ptr_ = nullptr; + } + return *this; + } + pointer get() const noexcept { return ptr_;