Skip to content

Commit f675d68

Browse files
<format>: Fix signed/unsigned mismatch in _In_bounds. (#1875)
1 parent c33874c commit f675d68

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

stl/inc/format

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,17 +2049,12 @@ inline void _Buffer_to_uppercase(char* _Begin, const char* _End) {
20492049
}
20502050
}
20512051

2052+
template <class _Ty>
2053+
using _Make_standard_integer = conditional_t<is_signed_v<_Ty>, make_signed_t<_Ty>, make_unsigned_t<_Ty>>;
2054+
20522055
template <class _CharT, integral _Ty>
20532056
_NODISCARD constexpr bool _In_bounds(const _Ty _Value) {
2054-
if constexpr (is_unsigned_v<_CharT> && is_unsigned_v<_Ty>) {
2055-
return _Value <= (numeric_limits<_CharT>::max)();
2056-
} else if constexpr (is_unsigned_v<_CharT>) {
2057-
return _Value >= 0 && static_cast<make_unsigned_t<_Ty>>(_Value) <= (numeric_limits<_CharT>::max)();
2058-
} else if constexpr (is_unsigned_v<_Ty>) {
2059-
return _Value <= static_cast<make_unsigned_t<_CharT>>((numeric_limits<_CharT>::max)());
2060-
} else {
2061-
return (numeric_limits<_CharT>::min)() <= _Value && _Value <= (numeric_limits<_CharT>::max)();
2062-
}
2057+
return _STD in_range<_Make_standard_integer<_CharT>>(static_cast<_Make_standard_integer<_Ty>>(_Value));
20632058
}
20642059

20652060
_NODISCARD inline int _Count_separators(size_t _Digits, const string_view _Groups) {

0 commit comments

Comments
 (0)