From 34018b2b65827a2cec96ea4337eb19167937bc8a Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 4 Feb 2015 12:17:14 +0200 Subject: [PATCH] shared_ptr: Fix assignment of polymorphic types Fix the assignment operator to work with polymorphic types. Suggested by Nadav. Signed-off-by: Pekka Enberg --- core/shared_ptr.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/shared_ptr.hh b/core/shared_ptr.hh index fd77c32060..4fec292d35 100644 --- a/core/shared_ptr.hh +++ b/core/shared_ptr.hh @@ -326,7 +326,7 @@ public: } template ::value>> shared_ptr& operator=(const shared_ptr& x) noexcept { - if (this != &x) { + if (*this != x) { this->~shared_ptr(); new (this) shared_ptr(x); } @@ -334,7 +334,7 @@ public: } template ::value>> shared_ptr& operator=(shared_ptr&& x) noexcept { - if (this != &x) { + if (*this != x) { this->~shared_ptr(); new (this) shared_ptr(std::move(x)); }