From 27e40a7f22b40774362fb1ae230d354dc76ab149 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 7 Feb 2022 20:15:55 +0700 Subject: [PATCH 1/2] resize_and_overwrite: fix warning C4018 --- stl/inc/xstring | 4 ++-- tests/std/tests/P0980R1_constexpr_strings/test.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 9398b7a7ab3..8fbe3503d0a 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -3972,9 +3972,9 @@ public: const auto _Result_size = _STD move(_Op)(_Mypair._Myval2._Myptr(), _New_size); #if _CONTAINER_DEBUG_LEVEL > 0 _STL_VERIFY(_Result_size >= 0, "the returned size can't be smaller than 0"); - _STL_VERIFY(_Result_size <= _New_size, "the returned size can't be greater than the passed size"); + _STL_VERIFY(cmp_less_equal(_Result_size, _New_size), "the returned size can't be greater than the passed size"); #endif // _CONTAINER_DEBUG_LEVEL > 0 - _Eos(_Result_size); + _Eos(static_cast(_Result_size)); } #endif // _HAS_CXX23 diff --git a/tests/std/tests/P0980R1_constexpr_strings/test.cpp b/tests/std/tests/P0980R1_constexpr_strings/test.cpp index 3a09cf260b7..e484f2da4b8 100644 --- a/tests/std/tests/P0980R1_constexpr_strings/test.cpp +++ b/tests/std/tests/P0980R1_constexpr_strings/test.cpp @@ -2383,6 +2383,19 @@ constexpr void test_all() { static_assert(test_allocator_awareness()); } +#if _HAS_CXX23 +void test_gh_2524() // COMPILE-ONLY +{ + // 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; + return i; + }); +} +#endif // _HAS_CXX23 + int main() { test_all(); #ifdef __cpp_char8_t From 62e42c559ecee95bbb3c27e9170124450481f465 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 7 Feb 2022 21:52:53 +0700 Subject: [PATCH 2/2] easy way of fixing the warning Co-authored-by: PowerGamer1 --- stl/inc/xstring | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 8fbe3503d0a..3ec6219b532 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -3972,7 +3972,8 @@ public: const auto _Result_size = _STD move(_Op)(_Mypair._Myval2._Myptr(), _New_size); #if _CONTAINER_DEBUG_LEVEL > 0 _STL_VERIFY(_Result_size >= 0, "the returned size can't be smaller than 0"); - _STL_VERIFY(cmp_less_equal(_Result_size, _New_size), "the returned size can't be greater than the passed size"); +#pragma warning(suppress : 4018) // '<=': signed/unsigned mismatch, we already compared with 0, so it's safe + _STL_VERIFY(_Result_size <= _New_size, "the returned size can't be greater than the passed size"); #endif // _CONTAINER_DEBUG_LEVEL > 0 _Eos(static_cast(_Result_size)); }