summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-02-18 11:45:45 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-21 15:28:40 +0100
commit3a8da4a4843d787e9bf12973bf1fcf4da793558d (patch)
tree9a87d13388a5a83213df03af84531f6046d2375c
parent6a6178702e8af97b943c728f1cb4ab20233835a2 (diff)
QEasingCurve: implement move constructor
The move constructor sets other.d_ptr to zero. This is safe, because after being moved from, the object is left in a state in which it can be safely destroyed (delete nullptr is a no-op). It cannot meaningfully be used anymore (most members will crash with a nullptr dereference), but in most cases, the moved-from object cannot be accessed anyway (not a named object), and if a named object is moved from, it must have been through explicit std::move(), as in the test case. The STL makes better guarantees (moved-from containers are .empty()), but I don't think it's worth introducing a null state into QEasingCurve just for supporting a use-case that should be considered a bug anyway. Change-Id: I4115b7386cdea6960507da6843a0d0196d8e4139 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qeasingcurve.h1
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp6
2 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/tools/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h
index 33d7c6934e..64e4027fc4 100644
--- a/src/corelib/tools/qeasingcurve.h
+++ b/src/corelib/tools/qeasingcurve.h
@@ -84,6 +84,7 @@ public:
QEasingCurve &operator=(const QEasingCurve &other);
#ifdef Q_COMPILER_RVALUE_REFS
+ QEasingCurve(QEasingCurve &&other) : d_ptr(other.d_ptr) { other.d_ptr = 0; }
QEasingCurve &operator=(QEasingCurve &&other)
{ qSwap(d_ptr, other.d_ptr); return *this; }
#endif
diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
index 1d4e91dc00..40e3cd08b6 100644
--- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
+++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
@@ -780,6 +780,12 @@ void tst_QEasingCurve::cpp11()
#ifdef Q_COMPILER_RVALUE_REFS
{
QEasingCurve ec( QEasingCurve::InOutBack );
+ QEasingCurve copy = std::move(ec); // move ctor
+ QCOMPARE( copy.type(), QEasingCurve::InOutBack );
+ QVERIFY( *reinterpret_cast<void**>(&ec) == 0 );
+ }
+ {
+ QEasingCurve ec( QEasingCurve::InOutBack );
QEasingCurve copy;
const QEasingCurve::Type type = copy.type();
copy = std::move(ec); // move assignment op