summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-03-25 15:29:17 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-03-27 07:56:15 +0000
commit66e147309698d8cc5ce7da10d4cd2e1e216c3786 (patch)
tree28bcc417f3201401c843fb4b94babff54f7b1c07
parent4413f7070aa0a1b16944de552a72d7fe62681b1c (diff)
Use move more consistently in QScopedValueRollback
Use move on the existing value as well so the constructor makes more of a difference. Change-Id: Iee2080da7b7d2d88eb108f0448c61423c7256979 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qscopedvaluerollback.h14
-rw-r--r--tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp13
2 files changed, 20 insertions, 7 deletions
diff --git a/src/corelib/tools/qscopedvaluerollback.h b/src/corelib/tools/qscopedvaluerollback.h
index 5f76269388..f904b8dfcb 100644
--- a/src/corelib/tools/qscopedvaluerollback.h
+++ b/src/corelib/tools/qscopedvaluerollback.h
@@ -48,20 +48,20 @@ template <typename T>
class QScopedValueRollback
{
public:
- explicit QScopedValueRollback(T &var) :
- varRef(var), oldValue(var)
+ explicit QScopedValueRollback(T &var)
+ : varRef(var), oldValue(var)
{
}
- explicit QScopedValueRollback(T &var, T value) :
- varRef(var), oldValue(var)
+ explicit QScopedValueRollback(T &var, T value)
+ : varRef(var), oldValue(std::move(var))
{
- varRef = qMove(value);
+ varRef = std::move(value);
}
~QScopedValueRollback()
{
- varRef = qMove(oldValue);
+ varRef = std::move(oldValue);
}
void commit()
@@ -70,7 +70,7 @@ public:
}
private:
- T& varRef;
+ T &varRef;
T oldValue;
Q_DISABLE_COPY(QScopedValueRollback)
diff --git a/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp b/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
index 656dd6a6e3..9b607db608 100644
--- a/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
+++ b/tests/auto/corelib/tools/qscopedvaluerollback/tst_qscopedvaluerollback.cpp
@@ -46,6 +46,7 @@ private Q_SLOTS:
void rollbackToPreviousCommit();
void exceptions();
void earlyExitScope();
+ void moveOnly();
private:
void earlyExitScope_helper(int exitpoint, int &member);
};
@@ -190,5 +191,17 @@ void tst_QScopedValueRollback::earlyExitScope_helper(int exitpoint, int& member)
r.commit();
}
+void tst_QScopedValueRollback::moveOnly()
+{
+ std::unique_ptr<int> uniquePtr;
+ std::unique_ptr<int> newVal(new int(5));
+ QVERIFY(!uniquePtr);
+ {
+ QScopedValueRollback<std::unique_ptr<int>> r(uniquePtr, std::move(newVal));
+ QVERIFY(uniquePtr);
+ }
+ QVERIFY(!uniquePtr);
+}
+
QTEST_MAIN(tst_QScopedValueRollback)
#include "tst_qscopedvaluerollback.moc"