@@ -71,9 +71,50 @@ TEST_CONSTEXPR_CXX20 bool tests() {
7171 return true ;
7272}
7373
74+ #if TEST_STD_VER >= 23
75+ std::size_t min_bytes = 1000 ;
76+
77+ template <typename T>
78+ struct increasing_allocator {
79+ using value_type = T;
80+ increasing_allocator () = default ;
81+ template <typename U>
82+ increasing_allocator (const increasing_allocator<U>&) noexcept {}
83+ std::allocation_result<T*> allocate_at_least (std::size_t n) {
84+ std::size_t allocation_amount = n * sizeof (T);
85+ if (allocation_amount < min_bytes)
86+ allocation_amount = min_bytes;
87+ min_bytes += 1000 ;
88+ return {static_cast <T*>(::operator new (allocation_amount)), allocation_amount};
89+ }
90+ T* allocate (std::size_t n) { return allocate_at_least (n).ptr ; }
91+ void deallocate (T* p, std::size_t ) noexcept { ::operator delete (static_cast <void *>(p)); }
92+ };
93+
94+ template <typename T, typename U>
95+ bool operator ==(increasing_allocator<T>, increasing_allocator<U>) {
96+ return true ;
97+ }
98+
99+ // https://github.com/llvm/llvm-project/issues/95161
100+ void test_increasing_allocator () {
101+ std::vector<int , increasing_allocator<int >> v;
102+ v.push_back (1 );
103+ assert (is_contiguous_container_asan_correct (v));
104+ std::size_t capacity = v.capacity ();
105+ v.shrink_to_fit ();
106+ assert (v.capacity () == capacity);
107+ assert (v.size () == 1 );
108+ assert (is_contiguous_container_asan_correct (v));
109+ }
110+ #endif // TEST_STD_VER >= 23
111+
74112int main (int , char **)
75113{
76114 tests ();
115+ #if TEST_STD_VER >= 23
116+ test_increasing_allocator ();
117+ #endif
77118#if TEST_STD_VER > 17
78119 static_assert (tests ());
79120#endif
0 commit comments