diff options
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 2 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/tst_qsharedpointer.cpp | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 4216456..95864a1 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -378,10 +378,10 @@ namespace QtSharedPointer { inline void internalFinishConstruction(T *ptr) { Basic<T>::internalConstruct(ptr); - if (ptr) d->setQObjectShared(ptr, true); #ifdef QT_SHAREDPOINTER_TRACK_POINTERS if (ptr) internalSafetyCheckAdd2(d, ptr); #endif + if (ptr) d->setQObjectShared(ptr, true); } inline ExternalRefCount() : d(0) { } diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp index 452e658..54fe65e 100644 --- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp @@ -1755,6 +1755,13 @@ void tst_QSharedPointer::invalidConstructs_data() "QSharedPointer<Data> ptr1 = QSharedPointer<Data>(aData);\n" "QSharedPointer<Data> ptr2 = QSharedPointer<Data>(aData);\n"; + // two QObjects with the same pointer + QTest::newRow("same-pointer-to-qobject") + << &QTest::QExternalTest::tryRunFail + << "QObject *anObj = new QObject;\n" + "QSharedPointer<QObject> ptr1 = QSharedPointer<QObject>(anObj);\n" + "QSharedPointer<QObject> ptr2 = QSharedPointer<QObject>(anObj);\n"; + // re-creation: QTest::newRow("re-creation") << &QTest::QExternalTest::tryRunFail |