Skip to content

Commit c761d14

Browse files
Add missing Mandates for resize_and_overwrite
1 parent af4f9c8 commit c761d14

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

stl/inc/xstring

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,9 +2317,11 @@ public:
23172317
_Mypair._Myval2._Mysize = _New_size;
23182318
}
23192319

2320-
auto _Arg_ptr = _Mypair._Myval2._Myptr();
2321-
auto _Arg_size = _New_size;
2322-
const auto _Result_size = _STD move(_Op)(_Arg_ptr, _Arg_size);
2320+
auto _Arg_ptr = _Mypair._Myval2._Myptr();
2321+
auto _Arg_size = _New_size;
2322+
const auto _Result_size = _STD move(_Op)(_Arg_ptr, _Arg_size);
2323+
static_assert(_Integer_like<decltype(_Result_size)>, "the return type of the operation must be integer-like");
2324+
23232325
const auto _Result_as_size_type = static_cast<size_type>(_Result_size);
23242326
#if _ITERATOR_DEBUG_LEVEL != 0
23252327
_STL_VERIFY(_Result_size >= 0, "the returned size can't be smaller than 0");

tests/std/tests/P0980R1_constexpr_strings/test.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include <type_traits>
1818
#include <utility>
1919

20+
#if _HAS_CXX20
21+
#include <ranges> // for integer-class types
22+
#endif // _HAS_CXX20
23+
2024
using namespace std;
2125

2226
constexpr auto literal_input = "Hello fluffy kittens";
@@ -2226,15 +2230,41 @@ constexpr void test_all() {
22262230
}
22272231

22282232
#if _HAS_CXX23
2233+
template <class I>
22292234
void test_gh_2524() { // COMPILE-ONLY
22302235
// GH-2524 resize_and_overwrite generates warning C4018 when Operation returns int
22312236
string s;
22322237
s.resize_and_overwrite(1, [](char* buffer, size_t) {
22332238
*buffer = 'x';
2234-
int i = 1;
2239+
I i = 1;
22352240
return i;
22362241
});
22372242
}
2243+
2244+
void test_gh_2524_all() { // COMPILE-ONLY
2245+
test_gh_2524<signed char>();
2246+
test_gh_2524<short>();
2247+
test_gh_2524<int>();
2248+
test_gh_2524<long>();
2249+
test_gh_2524<long long>();
2250+
2251+
test_gh_2524<unsigned char>();
2252+
test_gh_2524<unsigned short>();
2253+
test_gh_2524<unsigned int>();
2254+
test_gh_2524<unsigned long>();
2255+
test_gh_2524<unsigned long long>();
2256+
2257+
test_gh_2524<char>();
2258+
#ifdef __cpp_char8_t
2259+
test_gh_2524<char8_t>();
2260+
#endif // defined(__cpp_char8_t)
2261+
test_gh_2524<char16_t>();
2262+
test_gh_2524<char32_t>();
2263+
test_gh_2524<wchar_t>();
2264+
2265+
test_gh_2524<_Signed128>();
2266+
test_gh_2524<_Unsigned128>();
2267+
}
22382268
#endif // _HAS_CXX23
22392269

22402270
int main() {

0 commit comments

Comments
 (0)