Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include <limits> in <xutility> #3777

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
#include <cstdlib>
#include <cstring>

#if _HAS_CXX23
#include <limits>
#endif // _HAS_CXX23

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
Expand Down Expand Up @@ -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 <limits> 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);
}
Expand Down Expand Up @@ -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 <limits> dependency
constexpr auto _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 ^^^
}
Expand Down