diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-28 15:57:42 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-28 15:57:55 (GMT) |
commit | 31affef31b3743a23cf6f099d6a8f72b371586b4 (patch) | |
tree | 2083c23d547ae703df66441e1cb7c03ed9849374 | |
parent | 7621eec3fb023c7e477080b57c0aba858627091b (diff) | |
download | Qt-31affef31b3743a23cf6f099d6a8f72b371586b4.zip Qt-31affef31b3743a23cf6f099d6a8f72b371586b4.tar.gz Qt-31affef31b3743a23cf6f099d6a8f72b371586b4.tar.bz2 |
Mark the QSharedPointer with Qt::Uninitialized explicit
That ensures we don't create ambiguities. QSharedPointer shouldn't have
any implicit constructors.
Suggested-By: Olivier Goffart
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 2 | ||||
-rw-r--r-- | tests/auto/qsharedpointer/tst_qsharedpointer.cpp | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 90ca34f..e4f7ba9 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -511,7 +511,7 @@ public: QWeakPointer<T> toWeakRef() const; protected: - inline QSharedPointer(Qt::Initialization i) : BaseClass(i) {} + inline explicit QSharedPointer(Qt::Initialization i) : BaseClass(i) {} public: static inline QSharedPointer<T> create() diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp index 93f5b6e..d3df376 100644 --- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp @@ -548,6 +548,13 @@ class OtherObject: public QObject void tst_QSharedPointer::qobjectWeakManagement() { { + QWeakPointer<QObject> weak; + weak = QWeakPointer<QObject>(); + QVERIFY(weak.isNull()); + QVERIFY(!weak.data()); + } + + { QObject *obj = new QObject; QWeakPointer<QObject> weak(obj); QVERIFY(!weak.isNull()); @@ -1661,6 +1668,11 @@ void tst_QSharedPointer::invalidConstructs_data() << "QObject *ptr = new QObject;\n" "QWeakPointer<QObject> weak = ptr;\n" // this makes the object unmanaged "QSharedPointer<QObject> shared(ptr);\n"; + + QTest::newRow("shared-pointer-implicit-from-uninitialized") + << &QTest::QExternalTest::tryCompileFail + << "Data *ptr = 0;\n" + "QSharedPointer<Data> weakptr = Qt::Uninitialized;\n"; } void tst_QSharedPointer::invalidConstructs() |