diff --git a/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp index b39245cab7bf4..f8bcee31964bb 100644 --- a/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp @@ -39,11 +39,54 @@ TEST_CONSTEXPR_CXX20 bool tests() return true; } +#if TEST_STD_VER >= 23 +template +struct increasing_allocator { + using value_type = T; + std::size_t min_elements = 1000; + increasing_allocator() = default; + + template + constexpr increasing_allocator(const increasing_allocator& other) noexcept : min_elements(other.min_elements) {} + + constexpr std::allocation_result allocate_at_least(std::size_t n) { + if (n < min_elements) + n = min_elements; + min_elements += 1000; + return std::allocator{}.allocate_at_least(n); + } + constexpr T* allocate(std::size_t n) { return allocate_at_least(n).ptr; } + constexpr void deallocate(T* p, std::size_t n) noexcept { std::allocator{}.deallocate(p, n); } +}; + +template +bool operator==(increasing_allocator, increasing_allocator) { + return true; +} + +// https://github.com/llvm/llvm-project/issues/95161 +constexpr bool test_increasing_allocator() { + std::vector> v; + v.push_back(1); + std::size_t capacity = v.capacity(); + v.shrink_to_fit(); + assert(v.capacity() <= capacity); + assert(v.size() == 1); + + return true; +} +#endif // TEST_STD_VER >= 23 + int main(int, char**) { - tests(); + tests(); #if TEST_STD_VER > 17 static_assert(tests()); #endif +#if TEST_STD_VER >= 23 + test_increasing_allocator(); + static_assert(test_increasing_allocator()); +#endif // TEST_STD_VER >= 23 + return 0; }