Skip to content

Commit 01090a7

Browse files
Fix warning C4018: '<': signed/unsigned mismatch
Again, `(_Urng::max) () - (_Urng::min) ()` is `result_type - result_type`, subject to the usual arithmetic conversions. When compared against `_Udiff _Bmask_local`, this can emit signed/unsigned mismatch warnings. (This repro is x86-specific because MSVC emits warning C4018 at level 3 for `int < unsigned int`. `int < unsigned long long` emits an off-by-default warning C4388 "signed/unsigned mismatch". So even though the warning behavior is architecture-neutral, the varying size of `_Udiff` causes the warning to be x86-specific.) I'm avoiding extracting the `max - min` as a constant to avoid VSO-2580691 "`/analyze` emits bogus warning C6295 (Loop executes infinitely) for a loop that immediately finishes".
1 parent fedbd6c commit 01090a7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stl/inc/algorithm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6112,7 +6112,7 @@ private:
61126112
static constexpr size_t _Calc_bits() {
61136113
auto _Bits_local = _Udiff_bits;
61146114
auto _Bmask_local = static_cast<_Udiff>(-1);
6115-
for (; (_Urng::max) () - (_Urng::min) () < _Bmask_local; _Bmask_local >>= 1) {
6115+
for (; static_cast<_Udiff>((_Urng::max) () - (_Urng::min) ()) < _Bmask_local; _Bmask_local >>= 1) {
61166116
--_Bits_local;
61176117
}
61186118

0 commit comments

Comments
 (0)