diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-11-05 11:24:44 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-11-06 00:05:15 +0100 |
commit | 570485be95275f8535f65d1de0668c6037e02ee0 (patch) | |
tree | 006d7fb9a75a45487da0543b3cb6417f94caa9bc /src/corelib/tools/qarraydataops.h | |
parent | a07598e47ba4359accd6d0a8060d37f1e03db550 (diff) |
QArrayDataOps: fix QList range ctors with mixed value_type in C++20 builds
The QList<X> range ctor is supposed to accept iterators with
value_types convertible to X, e.g. tst_qitemselectionrange passes
iterator to a container of QModelIndex to the ctor of a
QList<QPersistentModelIndex>. But copyAppend() is not a template, so
trying to pass QModelIndex* when QPersistentModelIndex* is expected
errors out.
Fix by taking the copyAppend() path only if the types match.
Amends 507be11303c8dd9709d903f8e5ec197be66209ce.
Change-Id: I5e3ff84a80dc05dafde5572463b33df9002c8fe0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydataops.h')
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 173e3cac2e..9570ab28b8 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -912,10 +912,17 @@ public: Q_UNUSED(distance); #if __cplusplus >= 202002L - if constexpr ( - std::is_convertible_v< + constexpr bool canUseCopyAppend = std::conjunction_v< + std::is_convertible< typename std::iterator_traits<It>::iterator_category, - std::contiguous_iterator_tag>) { + std::contiguous_iterator_tag + >, + std::is_same< + std::remove_cv_t<typename std::iterator_traits<It>::value_type>, + T + > + >; + if constexpr (canUseCopyAppend) { this->copyAppend(std::to_address(b), std::to_address(e)); } else #endif |