From 570485be95275f8535f65d1de0668c6037e02ee0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 5 Nov 2021 11:24:44 +0100 Subject: [PATCH] QArrayDataOps: fix QList range ctors with mixed value_type in C++20 builds The QList 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. 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 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Andrei Golubev --- src/corelib/tools/qarraydataops.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 173e3cac2e8..9570ab28b8a 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::iterator_category, - std::contiguous_iterator_tag>) { + std::contiguous_iterator_tag + >, + std::is_same< + std::remove_cv_t::value_type>, + T + > + >; + if constexpr (canUseCopyAppend) { this->copyAppend(std::to_address(b), std::to_address(e)); } else #endif