From 548c2fbb3aa1ae6b7d3614b6381ea051977e2834 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 19 Jul 2017 15:22:15 +0200 Subject: QHash: make MSVC happy about the iterators passed to is_permutation MSVC warns about iterators being passed to certain Standard Library algorithms. dbd55cdaf367bdc9d6774bcb9927cbe19f18065f introduced a usa of std::is_permutation in a public header, which is causing such a warning to be emitted. To suppress the warning, Microsoft suggests to either use the 4-arg std::is_permutation overload (which however is not available in MSVC 2013) or to use a Standard Library extension, which we are already using elsewhere in Qt to deal with the same problem. However, that extension requires the iterator to be moved by size_t quantities, which isn't the case for QHash::iterator, and therefore generates more warnings about loss of precision (size_t -> int). Therefore, go with the 4-arg std::is_permutation, only on MSVC >= 2015. Change-Id: Idfcff28d14e0f1fde5d77f1deb9eec27c87ff5cd Task-number: QTBUG-61902 Reviewed-by: Thiago Macieira --- src/corelib/tools/qhash.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 035ec57957..703066857d 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -950,8 +950,22 @@ Q_OUTOFLINE_TEMPLATE bool QHash::operator==(const QHash &other) const return false; // Keys in the ranges are equal by construction; this checks only the values. - if (!std::is_permutation(it, thisEqualRangeEnd, otherEqualRange.first)) + // + // When using the 3-arg std::is_permutation, MSVC will emit warning C4996, + // passing an unchecked iterator to a Standard Library algorithm. We don't + // want to suppress the warning, and we can't use stdext::make_checked_array_iterator + // because QHash::(const_)iterator does not work with size_t and thus will + // emit more warnings. Use the 4-arg std::is_permutation instead (which + // is supported since MSVC 2015). + // + // ### Qt 6: if C++14 library support is a mandated minimum, remove the ifdef for MSVC. + if (!std::is_permutation(it, thisEqualRangeEnd, otherEqualRange.first +#if defined(Q_CC_MSVC) && _MSC_VER >= 1900 + , otherEqualRange.second +#endif + )) { return false; + } it = thisEqualRangeEnd; } -- cgit v1.2.3