From 028c367f757b98008bb9209252e5617758c88e0a Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 20 Mar 2023 16:57:27 +0100 Subject: [PATCH] Deprecate QtFuture::makeReadyFuture() [ChangeLog][Deprecation Notice][QtCore] The QtFuture::makeReadyFuture() method and all its specializations are deprecated since Qt 6.10. The reason for the deprecation is that the method has a makeReadyFuture(const QList &) overload, which behaves differently from all other overloads (including other non-const ref QList overloads). Use QtFuture::makeReadyVoidFuture() when you need a ready void QFuture, or QtFuture::makeReadyValueFuture() when you need to propagate the input type to the returned QFuture, or QtFuture::makeReadyRangeFuture() when you need to create a multi-value future based on an input container. Fixes: QTBUG-109677 Change-Id: I55125269989df0a02840d5ddd5763ef5f1070df5 Reviewed-by: Qt CI Bot Reviewed-by: Marc Mutz --- src/corelib/thread/qfuture.h | 3 +++ src/corelib/thread/qfuture.qdoc | 18 ++++++++++++++++++ src/corelib/thread/qfuture_impl.h | 4 ++++ .../corelib/thread/qfuture/tst_qfuture.cpp | 5 +++++ 4 files changed, 30 insertions(+) diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h index 219d3368f03..572c8054f9c 100644 --- a/src/corelib/thread/qfuture.h +++ b/src/corelib/thread/qfuture.h @@ -522,15 +522,18 @@ QFuture...>> whenAny(Futures &&... futures); #endif // Q_QDOC +#if QT_DEPRECATED_SINCE(6, 10) #if defined(Q_QDOC) static QFuture makeReadyFuture() #else template +QT_DEPRECATED_VERSION_X(6, 10, "Use makeReadyVoidFuture() instead") static QFuture makeReadyFuture() #endif { return makeReadyVoidFuture(); } +#endif // QT_DEPRECATED_SINCE(6, 10) } // namespace QtFuture diff --git a/src/corelib/thread/qfuture.qdoc b/src/corelib/thread/qfuture.qdoc index e9aabdda2de..7d0f639417a 100644 --- a/src/corelib/thread/qfuture.qdoc +++ b/src/corelib/thread/qfuture.qdoc @@ -973,6 +973,12 @@ \since 6.1 \overload + \deprecated [6.10] Use makeReadyValueFuture() instead + + The QtFuture::makeReadyFuture() method should be avoided because it has an + inconsistent set of overloads. It will be deprecated in future Qt releases. + Use QtFuture::makeReadyVoidFuture(), QtFuture::makeReadyValueFuture() or + QtFuture::makeReadyRangeFuture() instead. Creates and returns a QFuture which already has a result \a value. The returned QFuture has a type of std::decay_t, where T is not void. @@ -992,6 +998,12 @@ \since 6.1 \overload + \deprecated [6.10] Use makeReadyVoidFuture() instead + + The QtFuture::makeReadyFuture() method should be avoided because it has an + inconsistent set of overloads. It will be deprecated in future Qt releases. + Use QtFuture::makeReadyVoidFuture(), QtFuture::makeReadyValueFuture() or + QtFuture::makeReadyRangeFuture() instead. Creates and returns a void QFuture. Such QFuture can't store any result. One can use it to query the state of the computation. @@ -1015,6 +1027,12 @@ \since 6.1 \overload + \deprecated [6.10] Use makeReadyRangeFuture() instead + + The QtFuture::makeReadyFuture() method should be avoided because it has an + inconsistent set of overloads. It will be deprecated in future Qt releases. + Use QtFuture::makeReadyVoidFuture(), QtFuture::makeReadyValueFuture() or + QtFuture::makeReadyRangeFuture() instead. Creates and returns a QFuture which already has multiple results set from \a values. diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h index b282903405c..47a07801c7c 100644 --- a/src/corelib/thread/qfuture_impl.h +++ b/src/corelib/thread/qfuture_impl.h @@ -1009,7 +1009,9 @@ static QFuture> makeReadyValueFuture(T &&value) Q_CORE_EXPORT QFuture makeReadyVoidFuture(); // implemented in qfutureinterface.cpp +#if QT_DEPRECATED_SINCE(6, 10) template> +QT_DEPRECATED_VERSION_X(6, 10, "Use makeReadyValueFuture() instead") static QFuture> makeReadyFuture(T &&value) { return makeReadyValueFuture(std::forward(value)); @@ -1019,10 +1021,12 @@ static QFuture> makeReadyFuture(T &&value) // uses makeReadyVoidFuture() and required QFuture to be defined. template +QT_DEPRECATED_VERSION_X(6, 10, "Use makeReadyRangeFuture() instead") static QFuture makeReadyFuture(const QList &values) { return makeReadyRangeFuture(values); } +#endif // QT_DEPRECATED_SINCE(6, 10) #ifndef QT_NO_EXCEPTIONS diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index bb788988361..118a005de51 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -4078,6 +4078,9 @@ void tst_QFuture::rejectPendingResultOverwrite() void tst_QFuture::createReadyFutures() { +#if QT_DEPRECATED_SINCE(6, 10) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // using const T & { const int val = 42; @@ -4113,6 +4116,8 @@ void tst_QFuture::createReadyFutures() QCOMPARE(f.resultCount(), 3); QCOMPARE(f.results(), values); } +QT_WARNING_POP +#endif // QT_DEPRECATED_SINCE(6, 10) // test makeReadyValueFuture() {