diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index a9c6babbf58..5dfc4614f91 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -28,6 +28,7 @@ QT_END_NAMESPACE #include #include #include // for IsPointerToTypeDerivedFromQObject +#include #include @@ -537,6 +538,12 @@ class QWeakPointer template using IfCompatible = typename std::enable_if::value, bool>::type; + template + using IfVirtualBase = typename std::enable_if, bool>::type; + + template + using IfNotVirtualBase = typename std::enable_if, bool>::type; + public: typedef T element_type; typedef T value_type; @@ -566,7 +573,15 @@ public: } QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QWeakPointer) - template = true> + template = true, IfNotVirtualBase = true> + Q_NODISCARD_CTOR + QWeakPointer(QWeakPointer &&other) noexcept + : d(std::exchange(other.d, nullptr)), + value(std::exchange(other.value, nullptr)) + { + } + + template = true, IfVirtualBase = true> Q_NODISCARD_CTOR QWeakPointer(QWeakPointer &&other) noexcept : d(other.d), value(other.toStrongRef().get()) // must go through QSharedPointer, see below