QHash: make MSVC happy about the iterators passed to is_permutation
MSVC warns about iterators being passed to certain Standard Library
algorithms. dbd55cdaf3 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>
bb10
parent
82f701ed00
commit
548c2fbb3a
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue