[libcxx-commits] [libcxx] [libc++] Fix basic_string not allowing max_size() elements to be stored (PR #125423)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 5 08:31:33 PST 2025
================
----------------
ldionne wrote:
Refactoring suggestion for this test file:
```c++
template <class CharT, class Allocator>
TEST_CONSTEXPR_CXX20 void test_string() {
// all the tests here, including those for max_size().
// you probably need to use MAKE_STRING to handle wide characters
// This function:
// void test(S s, typename S::size_type n, S expected)
// can become a lambda or you can call it something like check_impl
// to make it clear it's just a throwaway helper.
{
...
}
{
// still hardcode the allocator here, whatever, it's still easier to understand the test that way
std::basic_string<CharT, std::char_traits<CharT>, tiny_size_allocator<32, CharT>> str;
}
}
TEST_CONSTEXPR_CXX20 bool test() {
test_string<std::string>();
#if TEST_STD_VER >= 11
test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
test_string<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#endif
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test_string<std::wstring>();
#endif
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
```
https://github.com/llvm/llvm-project/pull/125423
More information about the libcxx-commits
mailing list