Fix QtFuture::when{All,Any}() overload resolution
Both whenAll() and whenAny() have two overloads: * an overload taking two input iterators, e.g. whenAll(IntpuIt begin, InputIt end) * an overload taking an arbitrary number of future objects, e.g. whenAll(Futures &&... futures) The public APIs are properly constrained, but internally they call QtPrivate::when*Impl() template functions, that have the same two overloads, but do not have any constraints. As a result, passing exactly two QFuture<T>{} objects was leading to the compiler picking the Impl overload that takes a pair of iterators. Fix it by applying a subset of constraints from the public API to the private implementation as well. Amends 102f7d31c469a546f52c930a047bd294fb198186 which was introduced for Qt 6.3, so picking down to Qt 6.5. Fixes: QTBUG-131959 Pick-to: 6.8 6.5 Change-Id: Ide29ac9a494d07870e92957c40c1f614e56825f8 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 8aef5b0d8fd57684abe39c88af8c14d8882ef07b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
73b8c83ec7
commit
90fab1e4e9
@ -1106,7 +1106,9 @@ void addCompletionHandlers(const std::shared_ptr<ContextType> &context, const st
|
||||
addCompletionHandlersImpl<size - 1, ContextType, Ts...>(context, t);
|
||||
}
|
||||
|
||||
template<typename OutputSequence, typename InputIt, typename ValueType>
|
||||
template<typename OutputSequence, typename InputIt, typename ValueType,
|
||||
std::enable_if_t<std::conjunction_v<IsForwardIterable<InputIt>, isQFuture<ValueType>>,
|
||||
bool> = true>
|
||||
QFuture<OutputSequence> whenAllImpl(InputIt first, InputIt last)
|
||||
{
|
||||
const qsizetype size = std::distance(first, last);
|
||||
@ -1142,7 +1144,9 @@ QFuture<OutputSequence> whenAllImpl(Futures &&... futures)
|
||||
return context->promise.future();
|
||||
}
|
||||
|
||||
template<typename InputIt, typename ValueType>
|
||||
template<typename InputIt, typename ValueType,
|
||||
std::enable_if_t<std::conjunction_v<IsForwardIterable<InputIt>, isQFuture<ValueType>>,
|
||||
bool> = true>
|
||||
QFuture<QtFuture::WhenAnyResult<typename Future<ValueType>::type>> whenAnyImpl(InputIt first,
|
||||
InputIt last)
|
||||
{
|
||||
|
@ -233,6 +233,7 @@ private slots:
|
||||
void getFutureInterface();
|
||||
void convertQMetaType();
|
||||
|
||||
void whenAllwhenAnyOverloadResolution();
|
||||
void whenAllIterators();
|
||||
void whenAllIteratorsWithCanceled();
|
||||
void whenAllIteratorsWithFailed();
|
||||
@ -4447,6 +4448,14 @@ void tst_QFuture::convertQMetaType()
|
||||
QVERIFY(voidFuture.isFinished());
|
||||
}
|
||||
|
||||
void tst_QFuture::whenAllwhenAnyOverloadResolution()
|
||||
{
|
||||
// Compile-only test. These could fail to compile due to picking a wrong
|
||||
// overload of *Impl() methods. See QTBUG-131959
|
||||
[[maybe_unused]] auto f = QtFuture::whenAll(QFuture<void>{}, QFuture<void>{});
|
||||
[[maybe_unused]] auto ff = QtFuture::whenAny(QFuture<void>{}, QFuture<void>{});
|
||||
}
|
||||
|
||||
template<class OutputContainer>
|
||||
void testWhenAllIterators()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user