Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(_Result_size)>,
"the return type of the operation must be integer-like, N5014 [string.capacity]/8");

const auto _Result_as_size_type = static_cast<size_type>(_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);
}
Expand Down
32 changes: 31 additions & 1 deletion tests/std/tests/P0980R1_constexpr_strings/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <type_traits>
#include <utility>

#if _HAS_CXX23
#include <ranges> // for integer-class types in test_gh_2524_all()
#endif // _HAS_CXX23

using namespace std;

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

#if _HAS_CXX23
template <class I>
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<signed char>();
test_gh_2524<short>();
test_gh_2524<int>();
test_gh_2524<long>();
test_gh_2524<long long>();

test_gh_2524<unsigned char>();
test_gh_2524<unsigned short>();
test_gh_2524<unsigned int>();
test_gh_2524<unsigned long>();
test_gh_2524<unsigned long long>();

test_gh_2524<char>();
#ifdef __cpp_char8_t
test_gh_2524<char8_t>();
#endif // defined(__cpp_char8_t)
test_gh_2524<char16_t>();
test_gh_2524<char32_t>();
test_gh_2524<wchar_t>();

test_gh_2524<_Signed128>();
test_gh_2524<_Unsigned128>();
}
#endif // _HAS_CXX23

int main() {
Expand Down