summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-07-19 15:22:15 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-07-20 20:53:34 +0000
commit548c2fbb3aa1ae6b7d3614b6381ea051977e2834 (patch)
treec0b6f4ea9dd1ed99da2150ab8a5bd4723da144c2
parent82f701ed00546a01602413e90390388a1ec6dfbe (diff)
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 <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qhash.h16
1 files changed, 15 insertions, 1 deletions
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<Key, T>::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;
}