summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2020-10-30 11:21:01 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2020-10-30 17:19:26 +0100
commitff0ba7e2d7b91fd5809cb314935a1ca1a436f6c9 (patch)
treeb1a9ca252e2953c23fdd62645e231ef8f92b4ac9 /tests/auto/corelib/thread
parent48a13327c663a9e1409cc98936190f3d1565fcc2 (diff)
Forbid implicit conversions between QFuture and other types
- Remove the casting operator of QFuture<T> to T. It calls QFuture::result(), which may lead to undefined behavior if the user has moved the results from QFuture via QFuture::takeResult() before trying to do the conversion. - Disable implicit conversion of QFuture<T> to QFuture<void>, by making the constructor explicit. If the users really intend to do the conversion, they should do it explicitly. [ChangeLog][Source-Incompatible Changes][QFuture] Implicit conversions of QFuture<T> to T and to QFuture<void> have been disabled. Use QFuture::result() or QFuture::takeResult() where you need to convert QFuture<T> to T. Use the explicit QFuture<void>(const QFuture<T> &) constructor to convert QFuture<T> to QFuture<void>. Change-Id: I153d4137d36365b1611ac934fb3ac2eb667fdd6c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'tests/auto/corelib/thread')
-rw-r--r--tests/auto/corelib/thread/qfuture/tst_qfuture.cpp34
-rw-r--r--tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp2
2 files changed, 15 insertions, 21 deletions
diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
index 0faa8e0be7..18e11c35ad 100644
--- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
+++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
@@ -99,6 +99,7 @@ class tst_QFuture: public QObject
private slots:
void resultStore();
void future();
+ void futureToVoid();
void futureInterface();
void refcounting();
void cancel();
@@ -109,7 +110,6 @@ private slots:
void progressText();
void resultsAfterFinished();
void resultsAsList();
- void implicitConversions();
void iterators();
void iteratorsThread();
#if QT_DEPRECATED_SINCE(6, 0)
@@ -609,6 +609,19 @@ void tst_QFuture::future()
QCOMPARE(intFuture2.isFinished(), true);
}
+void tst_QFuture::futureToVoid()
+{
+ QPromise<int> p;
+ QFuture<int> future = p.future();
+
+ p.start();
+ p.setProgressValue(42);
+ p.finish();
+
+ QFuture<void> voidFuture = QFuture<void>(future);
+ QCOMPARE(voidFuture.progressValue(), 42);
+}
+
class IntResult : public QFutureInterface<int>
{
public:
@@ -1067,25 +1080,6 @@ void tst_QFuture::resultsAsList()
QCOMPARE(results, QList<int>() << 1 << 2);
}
-/*
- Test that QFuture<T> can be implicitly converted to T
-*/
-void tst_QFuture::implicitConversions()
-{
- QFutureInterface<QString> iface;
- iface.reportStarted();
-
- QFuture<QString> f(&iface);
-
- const QString input("FooBar 2000");
- iface.reportFinished(&input);
-
- const QString result = f;
- QCOMPARE(result, input);
- QCOMPARE(QString(f), input);
- QCOMPARE(static_cast<QString>(f), input);
-}
-
void tst_QFuture::iterators()
{
{
diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
index 027bd1313e..e83ea07dd4 100644
--- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
+++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
@@ -864,7 +864,7 @@ void tst_QFutureWatcher::suspendEvents()
void tst_QFutureWatcher::suspended()
{
- QFutureWatcher<void> watcher;
+ QFutureWatcher<int> watcher;
QSignalSpy resultReadySpy(&watcher, &QFutureWatcher<int>::resultReadyAt);
#if QT_DEPRECATED_SINCE(6, 0)
QT_WARNING_PUSH