mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-23 10:00:35 +00:00
shared_ptr: Fix assignment of polymorphic types
Fix the assignment operator to work with polymorphic types. Suggested by Nadav. Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
This commit is contained in:
@@ -326,7 +326,7 @@ public:
|
||||
}
|
||||
template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>>
|
||||
shared_ptr& operator=(const shared_ptr<U>& x) noexcept {
|
||||
if (this != &x) {
|
||||
if (*this != x) {
|
||||
this->~shared_ptr();
|
||||
new (this) shared_ptr(x);
|
||||
}
|
||||
@@ -334,7 +334,7 @@ public:
|
||||
}
|
||||
template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>>
|
||||
shared_ptr& operator=(shared_ptr<U>&& x) noexcept {
|
||||
if (this != &x) {
|
||||
if (*this != x) {
|
||||
this->~shared_ptr();
|
||||
new (this) shared_ptr(std::move(x));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user