diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-10-30 11:21:01 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-10-30 17:19:26 +0100 |
commit | ff0ba7e2d7b91fd5809cb314935a1ca1a436f6c9 (patch) | |
tree | b1a9ca252e2953c23fdd62645e231ef8f92b4ac9 /tests/auto/corelib/thread/qfuture/tst_qfuture.cpp | |
parent | 48a13327c663a9e1409cc98936190f3d1565fcc2 (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/qfuture/tst_qfuture.cpp')
-rw-r--r-- | tests/auto/corelib/thread/qfuture/tst_qfuture.cpp | 34 |
1 files changed, 14 insertions, 20 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() { { |