From 564a655b3f39e70561b04df2d20e2d522a6afa92 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sat, 17 Jun 2023 20:47:01 +0800 Subject: [PATCH 1/2] Don't include `` in `` --- stl/inc/xutility | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stl/inc/xutility b/stl/inc/xutility index 0e7933c44ad..6d7ca1633c8 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -14,10 +14,6 @@ #include #include -#if _HAS_CXX23 -#include -#endif // _HAS_CXX23 - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -7179,7 +7175,9 @@ _NODISCARD constexpr bool _Mul_overflow(const _Int _Left, const _Int _Right, _In #endif // __clang__ { if constexpr (!_Signed_integer_like<_Int>) { - const bool _Overflow = _Left != 0 && _Right > (numeric_limits<_Int>::max)() / _Left; + // use instead of numeric_limits::max; avoid dependency + constexpr auto _UInt_max = static_cast<_Int>(-1); + const bool _Overflow = _Left != 0 && _Right > _UInt_max / _Left; if (!_Overflow) { _Out = static_cast<_Int>(_Left * _Right); } @@ -7207,10 +7205,12 @@ _NODISCARD constexpr bool _Mul_overflow(const _Int _Left, const _Int _Right, _In return false; } + // use instead of numeric_limits::max; avoid dependency + constexpr _Int_max = static_cast<_UInt>(static_cast<_UInt>(-1) / 2); if (_Negative) { - return _ULeft > (static_cast<_UInt>((numeric_limits<_Int>::max)()) + _UInt{1}) / _URight; + return _ULeft > (_Int_max + _UInt{1}) / _URight; } else { - return _ULeft > static_cast<_UInt>((numeric_limits<_Int>::max)()) / _URight; + return _ULeft > _Int_max / _URight; } // ^^^ Based on llvm::MulOverflow ^^^ } From 7d6ab8cd65bfe6cbbb1074fcd20c82995b0c35b8 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sat, 17 Jun 2023 21:16:48 +0800 Subject: [PATCH 2/2] Missing `auto`! --- stl/inc/xutility | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/xutility b/stl/inc/xutility index 6d7ca1633c8..681fb49c0bc 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -7206,7 +7206,7 @@ _NODISCARD constexpr bool _Mul_overflow(const _Int _Left, const _Int _Right, _In } // use instead of numeric_limits::max; avoid dependency - constexpr _Int_max = static_cast<_UInt>(static_cast<_UInt>(-1) / 2); + constexpr auto _Int_max = static_cast<_UInt>(static_cast<_UInt>(-1) / 2); if (_Negative) { return _ULeft > (_Int_max + _UInt{1}) / _URight; } else {