From 3f6ed5566fcfbbba4cadfade460460f8ebf06ad3 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 3 Sep 2013 09:44:30 +0200 Subject: [PATCH] Revert "Implement move-ctor and move-assignment-op for QScopedPointer" This reverts commit 5b9006bbdba7dcab01b8e640554a7d7a4b64f76b. Also revert "Doc: Enable documentation for QScopedPointer's rvalue ref functions" This reverts commit 5f8416ec659b134db90df7e7f857db77fd27b6ab. Adding a move contructor to QScopedPointer makes no sense, because moving means 'escaping the scope', which breaks the fundamental point of QScopedPointer. Change-Id: I4ac1b108bf199af6e436fa1629aa2d3b93c27724 Reviewed-by: Lars Knoll --- src/corelib/tools/qscopedpointer.cpp | 25 --- src/corelib/tools/qscopedpointer.h | 13 -- .../tools/qscopedpointer/qscopedpointer.pro | 1 - .../qscopedpointer/tst_qscopedpointer.cpp | 155 ------------------ 4 files changed, 194 deletions(-) diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index 22155d6d3a..fb0025c1ff 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -133,31 +133,6 @@ QT_BEGIN_NAMESPACE Constructs this QScopedPointer instance and sets its pointer to \a p. */ -/*! - \fn QScopedPointer::QScopedPointer(QScopedPointer &&other) - - Move-constructs a QScopedPointer instance, making it point at the same - object that \a other was pointing to. \a other is reset to point to \c{NULL}. - - \since 5.2 -*/ - -/*! - \fn QScopedPointer &operator=(QScopedPointer &&other) - - Move-assigns \a other to this QScopedPointer instance, transferring the - ownership of the managed pointer to this instance. - - If \a other and this instance are actually the same object, this operator - does nothing. - - Otherwise, this instance is set to point to the object \a other - is pointing to, and \a other is set to point to \c{NULL}. - If this instance was pointing to an object, that object is destroyed. - - \since 5.2 -*/ - /*! \fn QScopedPointer::~QScopedPointer() diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index dba37dae23..dd6e5bd57b 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -109,19 +109,6 @@ public: Cleanup::cleanup(oldD); } -#ifdef Q_COMPILER_RVALUE_REFS - inline QScopedPointer(QScopedPointer &&other) - : d(other.take()) - { - } - - inline QScopedPointer &operator=(QScopedPointer &&other) - { - reset(other.take()); - return *this; - } -#endif - inline T &operator*() const { Q_ASSERT(d); diff --git a/tests/auto/corelib/tools/qscopedpointer/qscopedpointer.pro b/tests/auto/corelib/tools/qscopedpointer/qscopedpointer.pro index 48a3b9ee9c..5fa529e175 100644 --- a/tests/auto/corelib/tools/qscopedpointer/qscopedpointer.pro +++ b/tests/auto/corelib/tools/qscopedpointer/qscopedpointer.pro @@ -1,5 +1,4 @@ CONFIG += testcase parallel_test -contains(QT_CONFIG, c++11):CONFIG += c++11 TARGET = tst_qscopedpointer QT = core testlib SOURCES = tst_qscopedpointer.cpp diff --git a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp index cb0382eb66..66ea3e940c 100644 --- a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp +++ b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp @@ -42,8 +42,6 @@ #include #include -#include - /*! \class tst_QScopedPointer \internal @@ -75,7 +73,6 @@ private Q_SLOTS: void objectSize(); void comparison(); void array(); - void move(); // TODO instanciate on const object }; @@ -461,158 +458,6 @@ void tst_QScopedPointer::array() QCOMPARE(instCount, RefCounted::instanceCount.load()); } -#ifdef Q_COMPILER_RVALUE_REFS -struct CountedInteger -{ - CountedInteger(int i) : i(i) - { - ++instanceCount; - } - ~CountedInteger() - { - --instanceCount; - } - CountedInteger(const CountedInteger &c) - : i(c.i) - { - ++instanceCount; - } - - static int instanceCount; - int i; -}; - -int CountedInteger::instanceCount = 0; - -QScopedPointer returnScopedPointer(int i) -{ - return QScopedPointer(new CountedInteger(i)); -} -#endif - -void tst_QScopedPointer::move() -{ -#ifndef Q_COMPILER_RVALUE_REFS - QSKIP("This test requires rvalues refs"); -#else - QCOMPARE(CountedInteger::instanceCount, 0); - - { - QScopedPointer p = returnScopedPointer(42); - QVERIFY(!p.isNull()); - QCOMPARE(p->i, 42); - QCOMPARE(CountedInteger::instanceCount, 1); - - QScopedPointer q = returnScopedPointer(51); - QVERIFY(!q.isNull()); - QCOMPARE(q->i, 51); - QCOMPARE(CountedInteger::instanceCount, 2); - - q = returnScopedPointer(123); - QVERIFY(!q.isNull()); - QCOMPARE(q->i, 123); - QCOMPARE(CountedInteger::instanceCount, 2); - - p = std::move(q); - QVERIFY(!p.isNull()); - QCOMPARE(p->i, 123); - QVERIFY(q.isNull()); - QCOMPARE(CountedInteger::instanceCount, 1); - - p = std::move(q); - QVERIFY(p.isNull()); - QVERIFY(q.isNull()); - QCOMPARE(CountedInteger::instanceCount, 0); - } - - QCOMPARE(CountedInteger::instanceCount, 0); - - { - QScopedPointer p = returnScopedPointer(1024); - QVERIFY(!p.isNull()); - QCOMPARE(p->i, 1024); - QCOMPARE(CountedInteger::instanceCount, 1); - - p.reset(); - QVERIFY(p.isNull()); - QCOMPARE(CountedInteger::instanceCount, 0); - - p = returnScopedPointer(1024); - const CountedInteger * const rawPtr = p.data(); - p = std::move(p); - // now p is in a "valid, but unspecified state". so the test must not crash. - // we do actually know that this move should've been a noop. - QVERIFY(!p.isNull()); - QCOMPARE(p.data(), rawPtr); - QCOMPARE(p->i, 1024); - QCOMPARE(CountedInteger::instanceCount, 1); - - p.reset(); - QVERIFY(p.isNull()); - QCOMPARE(CountedInteger::instanceCount, 0); - } - - QCOMPARE(CountedInteger::instanceCount, 0); - - { - QScopedPointer p = returnScopedPointer(-1); - QVERIFY(!p.isNull()); - QCOMPARE(p->i, -1); - QCOMPARE(CountedInteger::instanceCount, 1); - } - - QCOMPARE(CountedInteger::instanceCount, 0); - - { - QScopedPointer p = returnScopedPointer(0); - QVERIFY(!p.isNull()); - QCOMPARE(p->i, 0); - QCOMPARE(CountedInteger::instanceCount, 1); - - QScopedPointer q; - QVERIFY(q.isNull()); - - p = std::move(q); - QVERIFY(p.isNull()); - QVERIFY(q.isNull()); - QCOMPARE(CountedInteger::instanceCount, 0); - } - - QCOMPARE(CountedInteger::instanceCount, 0); - - { - QScopedPointer p; - QVERIFY(p.isNull()); - QCOMPARE(CountedInteger::instanceCount, 0); - - QScopedPointer q = returnScopedPointer(123); - QVERIFY(!q.isNull()); - QCOMPARE(q->i, 123); - QCOMPARE(CountedInteger::instanceCount, 1); - - p = std::move(q); - QVERIFY(!p.isNull()); - QCOMPARE(p->i, 123); - QVERIFY(q.isNull()); - QCOMPARE(CountedInteger::instanceCount, 1); - } - - QCOMPARE(CountedInteger::instanceCount, 0); - - { - QScopedPointer p; - QVERIFY(p.isNull()); - QCOMPARE(CountedInteger::instanceCount, 0); - - p = returnScopedPointer(2001); - QVERIFY(!p.isNull()); - QCOMPARE(p->i, 2001); - QCOMPARE(CountedInteger::instanceCount, 1); - } - - QCOMPARE(CountedInteger::instanceCount, 0); -#endif -} QTEST_MAIN(tst_QScopedPointer) #include "tst_qscopedpointer.moc"