From 323b00e38c38cc864d136d70befd106400c50163 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 10 Feb 2018 10:08:16 -0800 Subject: QSharedDataPointer: use swap-and-move in the move constructor This makes the pointer that was in the moved-into object be destroyed before the return of this function (if the reference count was 1), instead of letting it live in the moved-from object. Task-number: QTBUG-66322 Change-Id: I3debfc11127e4516b505fffd151209292bd3adaa Reviewed-by: Lars Knoll --- src/corelib/tools/qshareddata.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index dbf0907a0f..780f2331a8 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -115,7 +115,11 @@ public: #ifdef Q_COMPILER_RVALUE_REFS QSharedDataPointer(QSharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = nullptr; } inline QSharedDataPointer &operator=(QSharedDataPointer &&other) Q_DECL_NOTHROW - { qSwap(d, other.d); return *this; } + { + QSharedDataPointer moved(std::move(other)); + swap(moved); + return *this; + } #endif inline bool operator!() const { return !d; } @@ -204,7 +208,11 @@ public: #ifdef Q_COMPILER_RVALUE_REFS inline QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) Q_DECL_NOTHROW : d(o.d) { o.d = nullptr; } inline QExplicitlySharedDataPointer &operator=(QExplicitlySharedDataPointer &&other) Q_DECL_NOTHROW - { qSwap(d, other.d); return *this; } + { + QExplicitlySharedDataPointer moved(std::move(other)); + swap(moved); + return *this; + } #endif inline bool operator!() const { return !d; } -- cgit v1.2.3