From 8f0d2e287468e07cfa5cd70273d57a7d78076a3e Mon Sep 17 00:00:00 2001 From: Dennis Oberst Date: Tue, 30 May 2023 17:50:58 +0200 Subject: [PATCH] QArrayDataPointer: add missing std::invoke call to projection To ensure the correct invocation of the projection function, this patch introduces the usage of std::invoke for all accesses to it. This modification expands the coverage to include cases where the callable object is a pointer to a member function. Amends: 7ca633d9a82f90e5bba5e12ba923bfb0a257af63. Change-Id: If666012d785ac74c8e856ea9be2a46b3307c8a06 Reviewed-by: Ivan Solovev --- src/corelib/tools/qarraydatapointer.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index eb6ceeafeef..ad9ca428de4 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -334,7 +334,7 @@ public: const auto capacityBegin = begin() - offset; const auto prependBufferEnd = begin(); - if constexpr (!std::is_nothrow_constructible_v) { + if constexpr (!std::is_nothrow_constructible_v) { // If construction can throw, and we have freeSpaceAtBegin(), // it's easiest to just clear the container and start fresh. // The alternative would be to keep track of two active, disjoint ranges. @@ -366,7 +366,8 @@ public: size = dst - begin(); return; } - q20::construct_at(dst, proj(*first)); // construct element in prepend buffer + // construct element in prepend buffer + q20::construct_at(dst, std::invoke(proj, *first)); ++dst; ++first; } @@ -383,12 +384,12 @@ public: break; } else { do { - (*this)->emplace(size, proj(*first)); + (*this)->emplace(size, std::invoke(proj, *first)); } while (++first != last); return; // size() is already correct (and dst invalidated)! } } - *dst = proj(*first); // overwrite existing element + *dst = std::invoke(proj, *first); // overwrite existing element ++dst; ++first; }