diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h index ada4445d43..66088054ef 100644 --- a/src/corelib/kernel/qpointer.h +++ b/src/corelib/kernel/qpointer.h @@ -33,9 +33,11 @@ public: // compiler-generated dtor is fine! template = true> - QPointer(QPointer &&other) noexcept : wp(std::move(other.wp)) {} + QPointer(QPointer &&other) noexcept + : wp(std::exchange(other.wp, nullptr).internalData(), true) {} template = true> - QPointer(const QPointer &other) noexcept : wp(other.wp) {} + QPointer(const QPointer &other) noexcept + : wp(other.wp.internalData(), true) {} #ifdef Q_QDOC // Stop qdoc from complaining about missing function diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp index 0af3723704..332cf6ab71 100644 --- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp +++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp @@ -52,7 +52,7 @@ void tst_QPointer::conversion() QFile file; QPointer pf = &file; QCOMPARE_EQ(pf, &file); - QPointer pio = pf; + QPointer pio = pf; QCOMPARE_EQ(pio, &file); QCOMPARE_EQ(pio.get(), &file); QCOMPARE_EQ(pio, pf); @@ -63,7 +63,7 @@ void tst_QPointer::conversion() QFile file; QPointer pf = &file; QCOMPARE_EQ(pf, &file); - QPointer pio = std::move(pf); + QPointer pio = std::move(pf); QCOMPARE_EQ(pf, nullptr); QCOMPARE_EQ(pio, &file); QCOMPARE_EQ(pio.get(), &file);