diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-05-18 17:28:12 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-05-20 17:11:15 +0200 |
commit | bd1023a824efeafbd48c79d4dfbdd5f017044ceb (patch) | |
tree | 49d7fb8e5e853f2fa6db5a8f066c3e285caf3bc7 /src/concurrent/qtconcurrentfilter.h | |
parent | fa01e0bd71b42f0887790598106893c558557b60 (diff) |
QtConcurrent: prevent conversion of ReduceOption to initial value
QtConcurrent map- and filter-reduce functions take an initial value,
which can be of any type that is convertable to the result type. The
side-effect of this is that the enum values passed as ReduceOptions can
be treated as an initial value (if they are convertable to the result
type) which will result into a wrong overload call. To avoid this, added
additional check to make sure that the initial value type doesn't match
with ReduceOption enum.
Note that this required including the qtconcurrentreducekernel.h header
in qtconcurrentfunctionwrappers.h (which contains compiler checks for
QtConcurrent) for accessing ReduceOption enum, so I had to get rid of
qtconcurrentfunctionwrappers.h include from qtconcurrentreducekernel.h
to avoid circular header includes. This, in turn, required moving the
QtPrivate::SequenceHolder helper type to qtconcurrentreducekernel.h,
which didn't belong to qtconcurrentfunctionwrappers.h anyway.
Pick-to: 6.3 6.2
Fixes: QTBUG-102999
Change-Id: Ieaa8ef2e4bd82ce2ada2e0af9a47b87b51d59e87
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/concurrent/qtconcurrentfilter.h')
-rw-r--r-- | src/concurrent/qtconcurrentfilter.h | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/src/concurrent/qtconcurrentfilter.h b/src/concurrent/qtconcurrentfilter.h index 86e9a531d2..e35c445b94 100644 --- a/src/concurrent/qtconcurrentfilter.h +++ b/src/concurrent/qtconcurrentfilter.h @@ -73,7 +73,8 @@ template <typename ResultType, typename Sequence, typename KeepFunctor, typename #else template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> #endif QFuture<ResultType> filteredReduced(QThreadPool *pool, Sequence &&sequence, @@ -95,7 +96,8 @@ template <typename ResultType, typename Sequence, typename KeepFunctor, typename #else template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> #endif QFuture<ResultType> filteredReduced(Sequence &&sequence, KeepFunctor &&keep, @@ -144,7 +146,8 @@ template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> QFuture<ResultType> filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep, @@ -163,7 +166,8 @@ template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> QFuture<ResultType> filteredReduced(Sequence &&sequence, KeepFunctor &&keep, ReduceFunctor &&reduce, @@ -211,7 +215,8 @@ template <typename ResultType, typename Iterator, typename KeepFunctor, typename #else template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> #endif QFuture<ResultType> filteredReduced(QThreadPool *pool, Iterator begin, @@ -233,7 +238,8 @@ template <typename ResultType, typename Iterator, typename KeepFunctor, typename #else template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> #endif QFuture<ResultType> filteredReduced(Iterator begin, Iterator end, @@ -281,7 +287,8 @@ QFuture<ResultType> filteredReduced(Iterator begin, template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> QFuture<ResultType> filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, @@ -300,7 +307,8 @@ template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0, typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> QFuture<ResultType> filteredReduced(Iterator begin, Iterator end, KeepFunctor &&keep, @@ -400,7 +408,8 @@ template <typename ResultType, typename Sequence, typename KeepFunctor, typename #else template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> #endif ResultType blockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, @@ -423,7 +432,8 @@ template <typename ResultType, typename Sequence, typename KeepFunctor, typename #else template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> #endif ResultType blockingFilteredReduced(Sequence &&sequence, KeepFunctor &&keep, @@ -475,7 +485,8 @@ template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> ResultType blockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep, @@ -495,7 +506,8 @@ template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> ResultType blockingFilteredReduced(Sequence &&sequence, KeepFunctor &&keep, ReduceFunctor &&reduce, @@ -547,7 +559,8 @@ template <typename ResultType, typename Iterator, typename KeepFunctor, typename #else template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> #endif ResultType blockingFilteredReduced(QThreadPool *pool, Iterator begin, @@ -570,7 +583,8 @@ template <typename ResultType, typename Iterator, typename KeepFunctor, typename #else template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> #endif ResultType blockingFilteredReduced(Iterator begin, Iterator end, @@ -621,7 +635,8 @@ ResultType blockingFilteredReduced(Iterator begin, template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> ResultType blockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep, @@ -640,7 +655,8 @@ template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0, typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, typename InitialValueType, - std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0> + std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, + int> = 0> ResultType blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor &&keep, |