From c761d1489d511358e7f8c9ebdfb1e6c0967528e1 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 26 Aug 2025 15:19:44 +0800 Subject: [PATCH 1/3] Add missing Mandates for `resize_and_overwrite` --- stl/inc/xstring | 8 +++-- .../tests/P0980R1_constexpr_strings/test.cpp | 32 ++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index b49bb137779..608b64e764e 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -2317,9 +2317,11 @@ 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"); + 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"); diff --git a/tests/std/tests/P0980R1_constexpr_strings/test.cpp b/tests/std/tests/P0980R1_constexpr_strings/test.cpp index 706ab1d0676..fd77a8eefeb 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_CXX20 +#include // for integer-class types +#endif // _HAS_CXX20 + 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() { From 5cfe9ae18301bec807c50a96e5214cd71a87fd18 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Sat, 6 Sep 2025 03:07:51 -0700 Subject: [PATCH 2/3] Cite the Standard (also pre-existing below). --- stl/inc/xstring | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 608b64e764e..265ffc64a8e 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -2320,12 +2320,14 @@ public: 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"); + 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); } From c4c9d81631f24b70719d7afbadd7b83ad881f8a7 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Sat, 6 Sep 2025 03:16:07 -0700 Subject: [PATCH 3/3] Include `` only when necessary. --- tests/std/tests/P0980R1_constexpr_strings/test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/std/tests/P0980R1_constexpr_strings/test.cpp b/tests/std/tests/P0980R1_constexpr_strings/test.cpp index fd77a8eefeb..cc3004253ab 100644 --- a/tests/std/tests/P0980R1_constexpr_strings/test.cpp +++ b/tests/std/tests/P0980R1_constexpr_strings/test.cpp @@ -17,9 +17,9 @@ #include #include -#if _HAS_CXX20 -#include // for integer-class types -#endif // _HAS_CXX20 +#if _HAS_CXX23 +#include // for integer-class types in test_gh_2524_all() +#endif // _HAS_CXX23 using namespace std;