diff --git a/stl/inc/xstring b/stl/inc/xstring index b49bb137779..265ffc64a8e 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -2317,13 +2317,17 @@ public: _Mypair._Myval2._Mysize = _New_size; } - auto _Arg_ptr = _Mypair._Myval2._Myptr(); - auto _Arg_size = _New_size; - const auto _Result_size = _STD move(_Op)(_Arg_ptr, _Arg_size); + auto _Arg_ptr = _Mypair._Myval2._Myptr(); + auto _Arg_size = _New_size; + const auto _Result_size = _STD move(_Op)(_Arg_ptr, _Arg_size); + static_assert(_Integer_like, + "the return type of the operation must be integer-like, N5014 [string.capacity]/8"); + const auto _Result_as_size_type = static_cast(_Result_size); #if _ITERATOR_DEBUG_LEVEL != 0 - _STL_VERIFY(_Result_size >= 0, "the returned size can't be smaller than 0"); - _STL_VERIFY(_Result_as_size_type <= _New_size, "the returned size can't be greater than the passed size"); + _STL_VERIFY(_Result_size >= 0, "the returned size can't be smaller than 0, N5014 [string.capacity]/9.2"); + _STL_VERIFY(_Result_as_size_type <= _New_size, + "the returned size can't be greater than the passed size, N5014 [string.capacity]/9.3"); #endif // _ITERATOR_DEBUG_LEVEL != 0 _Eos(_Result_as_size_type); } diff --git a/tests/std/tests/P0980R1_constexpr_strings/test.cpp b/tests/std/tests/P0980R1_constexpr_strings/test.cpp index 706ab1d0676..cc3004253ab 100644 --- a/tests/std/tests/P0980R1_constexpr_strings/test.cpp +++ b/tests/std/tests/P0980R1_constexpr_strings/test.cpp @@ -17,6 +17,10 @@ #include #include +#if _HAS_CXX23 +#include // for integer-class types in test_gh_2524_all() +#endif // _HAS_CXX23 + using namespace std; constexpr auto literal_input = "Hello fluffy kittens"; @@ -2226,15 +2230,41 @@ constexpr void test_all() { } #if _HAS_CXX23 +template void test_gh_2524() { // COMPILE-ONLY // GH-2524 resize_and_overwrite generates warning C4018 when Operation returns int string s; s.resize_and_overwrite(1, [](char* buffer, size_t) { *buffer = 'x'; - int i = 1; + I i = 1; return i; }); } + +void test_gh_2524_all() { // COMPILE-ONLY + test_gh_2524(); + test_gh_2524(); + test_gh_2524(); + test_gh_2524(); + test_gh_2524(); + + test_gh_2524(); + test_gh_2524(); + test_gh_2524(); + test_gh_2524(); + test_gh_2524(); + + test_gh_2524(); +#ifdef __cpp_char8_t + test_gh_2524(); +#endif // defined(__cpp_char8_t) + test_gh_2524(); + test_gh_2524(); + test_gh_2524(); + + test_gh_2524<_Signed128>(); + test_gh_2524<_Unsigned128>(); +} #endif // _HAS_CXX23 int main() {