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

Refactor <limits> usage #4634

Merged
merged 32 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5b7d561
Avoid including <limits> to improve throughput
AlexGuteniev Apr 27, 2024
7ed2d06
expect test failures
AlexGuteniev Apr 27, 2024
362cb22
lift the limit for internal helper for `<regex>`
AlexGuteniev Apr 27, 2024
04fee98
one more skip
AlexGuteniev Apr 27, 2024
228b235
specialize `_Max_limit` for 128 bit
AlexGuteniev Apr 27, 2024
5adceae
avoid `_In_range` in `_Convert_size`
AlexGuteniev Apr 27, 2024
e123f28
one more skip
AlexGuteniev Apr 27, 2024
dd292a8
restrict to `<tr1common>`
AlexGuteniev Apr 27, 2024
61a2844
upstream knows
AlexGuteniev Apr 27, 2024
6e66be7
Update stl/inc/xlocnum
AlexGuteniev Apr 28, 2024
2f80b87
Revert "restrict to `<tr1common>`" +
AlexGuteniev Apr 28, 2024
5894028
<utility> is already there
AlexGuteniev Apr 28, 2024
07a711a
Merge branch 'no_limits' of https://github.com/AlexGuteniev/STL into …
AlexGuteniev Apr 28, 2024
e5d63d3
le-xi-co-graphically sort lines
AlexGuteniev Apr 30, 2024
85900ec
Avoid breaking old code
AlexGuteniev May 1, 2024
8d3e8ad
Merge branch 'no_limits' of https://github.com/AlexGuteniev/STL into …
AlexGuteniev May 1, 2024
516e1f3
unexpect test failures
AlexGuteniev May 1, 2024
8fdf232
Some tests still fail
AlexGuteniev May 2, 2024
4c623a5
Add `_Min_limit` for `_Unsigned128` and `_Signed128`.
StephanTLavavej May 17, 2024
f2a6ab1
Add `_STD` qualification in `<mdspan>`.
StephanTLavavej May 17, 2024
bd59736
Restore inclusion: `<xlocnum>` needs `<climits>`.
StephanTLavavej May 17, 2024
82344d2
`_In_range`: Use it more often; we control all types.
StephanTLavavej May 17, 2024
40fd472
`in_range`: Use it in `<semaphore>` with bonus cleanups.
StephanTLavavej May 17, 2024
90651a6
`in_range`: Use it in `<format>` and chronat.
StephanTLavavej May 17, 2024
4b70a7e
`_Meow_limit`: Use it in `_Could_compare_equal_to_value_type`.
StephanTLavavej May 17, 2024
6040623
`_Max_limit`: Use it in `_Mul_overflow`.
StephanTLavavej May 17, 2024
1461144
Be daring, part 1: `<algorithm>` and `<vector>` are now unlimited.
StephanTLavavej May 17, 2024
5a62472
Be daring, part 2: FAIL the other tests fixed by LLVM-90345.
StephanTLavavej May 17, 2024
8af943a
Be daring, part 3: Add an escape hatch.
StephanTLavavej May 17, 2024
5440892
GH 4646 <xutility>: unify min/max limit
StephanTLavavej May 17, 2024
942ccef
Be less daring, comment why, partially resurrect GH 3631 "Don't inclu…
StephanTLavavej May 18, 2024
0841c99
No more libcxx FAILs.
StephanTLavavej May 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions stl/inc/__msvc_int128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,32 @@ struct common_type<_Unsigned128, _Signed128> {
using type = _Unsigned128;
};

template <class _Ty>
_NODISCARD constexpr _Ty _Min_limit() noexcept;

template <>
_NODISCARD constexpr _Unsigned128 _Min_limit<_Unsigned128>() noexcept {
return 0;
}

template <>
_NODISCARD constexpr _Signed128 _Min_limit<_Signed128>() noexcept {
return _Signed128{0ull, 1ull << 63};
}

template <class _Ty>
_NODISCARD constexpr _Ty _Max_limit() noexcept;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

template <>
_NODISCARD constexpr _Unsigned128 _Max_limit<_Unsigned128>() noexcept {
return _Unsigned128{~0ull, ~0ull};
}

template <>
_NODISCARD constexpr _Signed128 _Max_limit<_Signed128>() noexcept {
return _Signed128{~0ull, ~0ull >> 1};
}

#undef _STL_128_INTRINSICS
#undef _STL_128_DIV_INTRINSICS

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ _NODISCARD _CONSTEXPR20 _FwdIt search_n(
return _First;
}

if (static_cast<uintmax_t>(_Count) > static_cast<uintmax_t>((numeric_limits<_Iter_diff_t<_FwdIt>>::max)())) {
if (static_cast<uintmax_t>(_Count) > static_cast<uintmax_t>(_STD _Max_limit<_Iter_diff_t<_FwdIt>>())) {
// if the number of _Vals searched for is larger than the longest possible sequence, we can't find it
return _Last;
}
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/bitset
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public:
}
}

if (_Array[0] > ULONG_MAX) {
if (!_STD _In_range<unsigned long>(_Array[0])) {
_Xoflo();
}

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _NODISCARD basic_string<typename _Traits::char_type, _Traits, _Alloc> _Convert_w
basic_string<typename _Traits::char_type, _Traits, _Alloc> _Output(_Al);

if (!_Input.empty()) {
if (_Input.size() > static_cast<size_t>(INT_MAX)) {
if (!_STD _In_range<int>(_Input.size())) {
_Throw_system_error(errc::invalid_argument);
}

Expand Down Expand Up @@ -4790,7 +4790,7 @@ private:
_ParseContext& _Parse_ctx;

_NODISCARD static constexpr int _Verify_dynamic_arg_index_in_range(const size_t _Idx) {
if (_Idx > static_cast<size_t>((numeric_limits<int>::max)())) {
if (!_STD in_range<int>(_Idx)) {
_Throw_format_error("Dynamic width or precision index too large.");
}

Expand Down
3 changes: 1 addition & 2 deletions stl/inc/deque
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,7 @@ public:
}

_NODISCARD size_type max_size() const noexcept {
return (_STD min)(
static_cast<size_type>((numeric_limits<difference_type>::max)()), _Alty_traits::max_size(_Getal()));
return (_STD min)(static_cast<size_type>(_STD _Max_limit<difference_type>()), _Alty_traits::max_size(_Getal()));
}

void resize(_CRT_GUARDOVERFLOW size_type _Newsize) {
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/execution
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ _NODISCARD _FwdIt search_n(_ExPo&&, const _FwdIt _First, _FwdIt _Last, const _Di
return _Last;
}

if (static_cast<uintmax_t>(_Count) > static_cast<uintmax_t>((numeric_limits<_Iter_diff_t<_FwdIt>>::max)())) {
if (static_cast<uintmax_t>(_Count) > static_cast<uintmax_t>(_STD _Max_limit<_Iter_diff_t<_FwdIt>>())) {
// if the number of _Vals searched for is larger than the longest possible sequence, we can't find it
return _Last;
}
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace filesystem {
wstring _Output;

if (!_Input.empty()) {
if (_Input.size() > static_cast<size_t>(INT_MAX)) {
if (!_STD _In_range<int>(_Input.size())) {
_Throw_system_error(errc::invalid_argument);
}

Expand All @@ -64,7 +64,7 @@ namespace filesystem {
basic_string<typename _Traits::char_type, _Traits, _Alloc> _Output(_Al);

if (!_Input.empty()) {
if (_Input.size() > static_cast<size_t>(INT_MAX)) {
if (!_STD _In_range<int>(_Input.size())) {
_Throw_system_error(errc::invalid_argument);
}

Expand Down
11 changes: 5 additions & 6 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ _EMIT_STL_WARNING(STL4038, "The contents of <format> are available only with C++
#include <concepts>
#include <cstdint>
#include <iterator>
#include <limits>
#include <locale>
#include <stdexcept>
#include <xcall_once.h>
Expand Down Expand Up @@ -936,7 +935,7 @@ _NODISCARD constexpr const _CharT* _Parse_nonnegative_integer(
const _CharT* _First, const _CharT* _Last, unsigned int& _Value) {
_STL_INTERNAL_CHECK(_First != _Last && '0' <= *_First && *_First <= '9');

constexpr auto _Max_int = static_cast<unsigned int>((numeric_limits<int>::max)());
constexpr auto _Max_int = static_cast<unsigned int>(_STD _Max_limit<int>());
constexpr auto _Big_int = _Max_int / 10u;

_Value = 0;
Expand Down Expand Up @@ -1660,7 +1659,7 @@ template <class _Handler, class _FormatArg>
_NODISCARD constexpr int _Get_dynamic_specs(const _FormatArg _Arg) {
_STL_INTERNAL_STATIC_ASSERT(_Is_any_of_v<_Handler, _Width_checker, _Precision_checker>);
const unsigned long long _Val = _STD visit_format_arg(_Handler{}, _Arg);
if (_Val > static_cast<unsigned long long>((numeric_limits<int>::max)())) {
if (!_STD in_range<int>(_Val)) {
_Throw_format_error("Number is too big.");
}

Expand Down Expand Up @@ -1740,7 +1739,7 @@ private:
_ParseContext& _Parse_ctx;

_NODISCARD static constexpr int _Verify_dynamic_arg_index_in_range(const size_t _Idx) {
if (_Idx > static_cast<size_t>((numeric_limits<int>::max)())) {
if (!_STD in_range<int>(_Idx)) {
_Throw_format_error("Dynamic width or precision index too large.");
}

Expand Down Expand Up @@ -1823,7 +1822,7 @@ public:

template <class _CharT>
constexpr void _On_type(_CharT _Type) {
if (_Type < 0 || _Type > (numeric_limits<signed char>::max)()) {
if (_Type < 0 || _Type > _STD _Max_limit<signed char>()) {
_Throw_format_error("Invalid type specification.");
}
const char _Narrow_type = static_cast<char>(_Type);
Expand Down Expand Up @@ -3350,7 +3349,7 @@ _NODISCARD const _CharT* _Measure_string_prefix(const basic_string_view<_CharT>
_Measure_string_prefix_iterator<_CharT> _Pfx_iter(_First, _Last);
int _Estimated_width = 0; // the estimated width of [_First, _Pfx_iter)

constexpr auto _Max_int = (numeric_limits<int>::max)();
constexpr auto _Max_int = _STD _Max_limit<int>();

while (_Pfx_iter != default_sentinel) {
if (_Estimated_width == _Max_width && _Max_width >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/forward_list
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ public:

_NODISCARD size_type max_size() const noexcept {
return (_STD min)(
static_cast<size_type>((numeric_limits<difference_type>::max)()), _Alnode_traits::max_size(_Getal()));
static_cast<size_type>(_STD _Max_limit<difference_type>()), _Alnode_traits::max_size(_Getal()));
}

_NODISCARD_EMPTY_MEMBER bool empty() const noexcept {
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/functional
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,7 @@ void _Build_boyer_moore_delta_2_table(_Iter_diff_t<_RanItPat>* const _Shifts, co
return;
}

if ((numeric_limits<_Diff>::max)() - _Pat_size < _Pat_size) {
if (_STD _Max_limit<_Diff>() - _Pat_size < _Pat_size) {
_Xlength_error("Boyer-Moore pattern is too long");
}

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/istream
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private:

template <class = void>
void _Increment_gcount() noexcept {
if (_Chcount != (numeric_limits<streamsize>::max)()) {
if (_Chcount != _STD _Max_limit<streamsize>()) {
++_Chcount;
}
}
Expand Down Expand Up @@ -492,7 +492,7 @@ public:
_TRY_IO_BEGIN
for (;;) { // get a metacharacter if more room in buffer
int_type _Meta;
if (_Count != (numeric_limits<streamsize>::max)() && --_Count < 0) {
if (_Count != _STD _Max_limit<streamsize>() && --_Count < 0) {
break; // buffer full, quit
} else if (_Traits::eq_int_type(_Traits::eof(),
_Meta = _Myios::rdbuf()->sbumpc())) { // end of file, quit
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/list
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ public:

_NODISCARD size_type max_size() const noexcept {
return (_STD min)(
static_cast<size_type>((numeric_limits<difference_type>::max)()), _Alnode_traits::max_size(_Getal()));
static_cast<size_type>(_STD _Max_limit<difference_type>()), _Alnode_traits::max_size(_Getal()));
}

_NODISCARD_EMPTY_MEMBER bool empty() const noexcept {
Expand Down
3 changes: 1 addition & 2 deletions stl/inc/mdspan
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
_EMIT_STL_WARNING(STL4038, "The contents of <mdspan> are available only with C++23 or later.");
#else // ^^^ !_HAS_CXX23 / _HAS_CXX23 vvv
#include <array>
#include <limits>
#include <span>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -213,7 +212,7 @@ public:
requires (sizeof...(_OtherExtents) == rank())
&& ((_OtherExtents == dynamic_extent || _Extents == dynamic_extent || _OtherExtents == _Extents) && ...)
constexpr explicit(((_Extents != dynamic_extent && _OtherExtents == dynamic_extent) || ...)
|| (numeric_limits<index_type>::max)() < (numeric_limits<_OtherIndexType>::max)())
|| _STD _Max_limit<index_type>() < _STD _Max_limit<_OtherIndexType>())
extents(const extents<_OtherIndexType, _OtherExtents...>& _Other) noexcept
: extents(_Other, make_index_sequence<rank_dynamic()>{}) {}

Expand Down
8 changes: 4 additions & 4 deletions stl/inc/regex
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ int _Iter_compare(_FwdIt1 _First1, _FwdIt1 _Last1, _FwdIt2 _First2, _FwdIt2 _Las

inline bool _Is_word(unsigned char _UCh) {
// special casing char to avoid branches for std::regex in this path
static constexpr bool _Is_word_table[(numeric_limits<unsigned char>::max)() + 1] = {
static constexpr bool _Is_word_table[_STD _Max_limit<unsigned char>() + 1] = {
// X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF
/* 0X */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 1X */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down Expand Up @@ -2958,7 +2958,7 @@ void _Builder<_FwdIt, _Elem, _RxTraits>::_Add_named_class(typename _Regex_traits
bool _Negate) { // add contents of named class to bracket expression
_Node_class<_Elem, _RxTraits>* _Node = static_cast<_Node_class<_Elem, _RxTraits>*>(_Current);
_Add_elts(_Node, _Cl, _Negate);
if (_Bmp_max < static_cast<unsigned int>((numeric_limits<_Elem>::max)())) {
if (_Bmp_max < static_cast<unsigned int>(_STD _Max_limit<_Elem>())) {
_Node->_Classes = static_cast<_Regex_traits_base::char_class_type>(_Node->_Classes | _Cl);
}
}
Expand Down Expand Up @@ -3005,7 +3005,7 @@ void _Builder<_FwdIt, _Elem, _RxTraits>::_Add_equiv(_FwdIt _First, _FwdIt _Last,
_Node->_Small->_Mark(_Ch);
}
}
if (_Bmp_max < static_cast<unsigned int>((numeric_limits<_Elem>::max)())) { // map range
if (_Bmp_max < static_cast<unsigned int>(_STD _Max_limit<_Elem>())) { // map range
_Sequence<_Elem>** _Cur = _STD addressof(_Node->_Equiv);
_Char_to_elts(_First, _Last, _Diff, _Cur);
}
Expand Down Expand Up @@ -4330,7 +4330,7 @@ bool _Parser<_FwdIt, _Elem, _RxTraits>::_CharacterEscape() { // check for valid
return _IdentityEscape();
}

if ((numeric_limits<typename _RxTraits::_Uelem>::max)() < static_cast<unsigned int>(_Val)) {
if (_STD _Max_limit<typename _RxTraits::_Uelem>() < static_cast<unsigned int>(_Val)) {
_Error(regex_constants::error_escape);
}

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/semaphore
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ _NODISCARD unsigned long _Semaphore_remaining_timeout(const chrono::time_point<_
}

const auto _Rel_time = chrono::ceil<chrono::milliseconds>(_Abs_time - _Now);
static constexpr chrono::milliseconds _Ten_days{chrono::hours{24 * 10}};
static_assert(_Ten_days.count() < ULONG_MAX, "Bad sizing assumption");
constexpr chrono::milliseconds _Ten_days{chrono::hours{24 * 10}};
_STL_INTERNAL_STATIC_ASSERT(_STD in_range<unsigned long>(_Ten_days.count()));
if (_Rel_time >= _Ten_days) {
return static_cast<unsigned long>(_Ten_days.count());
}
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/spanstream
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected:
const auto _Baseoff = (_Mode & ios_base::out) && !(_Mode & ios_base::in)
? static_cast<off_type>(_Mysb::pptr() - _Mysb::pbase())
: static_cast<off_type>(_Buf.size());
if (_Off > (numeric_limits<off_type>::max)() - _Baseoff) { // overflow, _Baseoff is always non-negative
if (_Off > _STD _Max_limit<off_type>() - _Baseoff) { // overflow, _Baseoff is always non-negative
return pos_type{off_type{-1}}; // report failure
}

Expand Down
4 changes: 2 additions & 2 deletions stl/inc/utility
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ _NODISCARD constexpr bool _Cmp_greater_equal(const _Ty1 _Left, const _Ty2 _Right

template <class _Ty>
_NODISCARD constexpr _Ty _Min_limit() noexcept { // same as (numeric_limits<_Ty>::min)(), less throughput cost
_STL_INTERNAL_STATIC_ASSERT(_Is_standard_integer<_Ty>); // doesn't attempt to handle all types
_STL_INTERNAL_STATIC_ASSERT(is_integral_v<_Ty>); // doesn't attempt to handle all types
if constexpr (is_signed_v<_Ty>) {
constexpr auto _Unsigned_max = static_cast<make_unsigned_t<_Ty>>(-1);
return static_cast<_Ty>((_Unsigned_max >> 1) + 1); // well-defined, N4950 [conv.integral]/3
Expand All @@ -851,7 +851,7 @@ _NODISCARD constexpr _Ty _Min_limit() noexcept { // same as (numeric_limits<_Ty>

template <class _Ty>
_NODISCARD constexpr _Ty _Max_limit() noexcept { // same as (numeric_limits<_Ty>::max)(), less throughput cost
_STL_INTERNAL_STATIC_ASSERT(_Is_standard_integer<_Ty>); // doesn't attempt to handle all types
_STL_INTERNAL_STATIC_ASSERT(is_integral_v<_Ty>); // doesn't attempt to handle all types
if constexpr (is_signed_v<_Ty>) {
constexpr auto _Unsigned_max = static_cast<make_unsigned_t<_Ty>>(-1);
return static_cast<_Ty>(_Unsigned_max >> 1);
Expand Down
5 changes: 2 additions & 3 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -1874,8 +1874,7 @@ public:
}

_NODISCARD _CONSTEXPR20 size_type max_size() const noexcept {
return (_STD min)(
static_cast<size_type>((numeric_limits<difference_type>::max)()), _Alty_traits::max_size(_Getal()));
return (_STD min)(static_cast<size_type>(_STD _Max_limit<difference_type>()), _Alty_traits::max_size(_Getal()));
}

_NODISCARD _CONSTEXPR20 size_type capacity() const noexcept {
Expand Down Expand Up @@ -3149,7 +3148,7 @@ public:
}

_NODISCARD _CONSTEXPR20 size_type max_size() const noexcept {
constexpr auto _Diff_max = static_cast<size_type>((numeric_limits<difference_type>::max)());
constexpr auto _Diff_max = static_cast<size_type>(_STD _Max_limit<difference_type>());
const size_type _Ints_max = this->_Myvec.max_size();
if (_Ints_max > _Diff_max / _VBITS) { // max_size bound by difference_type limits
return _Diff_max;
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/xhash
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ struct _Hash_vec {
}

_NODISCARD size_type max_size() const noexcept {
return (_STD min)(static_cast<size_type>((numeric_limits<difference_type>::max)()),
_Aliter_traits::max_size(_Mypair._Get_first()));
return (_STD min)(
static_cast<size_type>(_STD _Max_limit<difference_type>()), _Aliter_traits::max_size(_Mypair._Get_first()));
}

_NODISCARD size_type capacity() const noexcept {
Expand Down
1 change: 1 addition & 0 deletions stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define _XLOCNUM_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
Expand Down
9 changes: 6 additions & 3 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#if _STL_COMPILER_PREPROCESSOR
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <new>
#include <xatomic.h>
#include <xutility>
Expand All @@ -18,6 +17,10 @@
#include <tuple>
#endif // _HAS_CXX20

#ifdef _LEGACY_CODE_ASSUMES_XMEMORY_INCLUDES_LIMITS
#include <limits>
#endif

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
Expand Down Expand Up @@ -606,7 +609,7 @@ struct _Normal_allocator_traits { // defines traits for allocators
if constexpr (_Has_max_size<_Alloc>::value) {
return _Al.max_size();
} else {
return (numeric_limits<size_type>::max)() / sizeof(value_type);
return _STD _Max_limit<size_type>() / sizeof(value_type);
}
}

Expand Down Expand Up @@ -1087,7 +1090,7 @@ _NODISCARD constexpr _Size_type _Convert_size(const _Unsigned_type _Len) noexcep
_STL_INTERNAL_STATIC_ASSERT(_Size_type(-1) > 0);

if constexpr (sizeof(_Unsigned_type) > sizeof(_Size_type)) {
if (_Len > (numeric_limits<_Size_type>::max)()) {
if (_Len > _STD _Max_limit<_Size_type>()) {
_Xlength_error("size is too long for _Size_type");
}
}
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -4151,7 +4151,7 @@ public:
const size_type _Alloc_max = _Alty_traits::max_size(_Getal());
const size_type _Storage_max = // can always store small string
(_STD max)(_Alloc_max, static_cast<size_type>(_BUF_SIZE));
return (_STD min)(static_cast<size_type>((numeric_limits<difference_type>::max)()),
return (_STD min)(static_cast<size_type>(_STD _Max_limit<difference_type>()),
_Storage_max - 1 // -1 is for null terminator and/or npos
);
}
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xtree
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ public:

_NODISCARD size_type max_size() const noexcept {
return (_STD min)(
static_cast<size_type>((numeric_limits<difference_type>::max)()), _Alnode_traits::max_size(_Getal()));
static_cast<size_type>(_STD _Max_limit<difference_type>()), _Alnode_traits::max_size(_Getal()));
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
}

_NODISCARD_EMPTY_MEMBER bool empty() const noexcept {
Expand Down