Skip to content

Commit 98d8c3e

Browse files
committed
Fix ASan new-delete-mismatch
1 parent 96f01dd commit 98d8c3e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libcxx/test/libcxx/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void test_oversizing_allocator() {
5151
assert(s.size() == size);
5252
}
5353

54-
// Ensure that the libc++ implementation of shrink_to_fit does NOT swap buffer with equal allocation sizes
54+
// Make sure libc++ shrink_to_fit does NOT swap buffer with equal allocation sizes
5555
void test_no_swap_with_equal_allocation_size() {
5656
{ // Test with custom allocator with a minimum allocation size
5757
std::basic_string<char, std::char_traits<char>, min_size_allocator<128, char> > s(

libcxx/test/support/increasing_allocator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class min_size_allocator {
6262
TEST_NODISCARD TEST_CONSTEXPR_CXX20 T* allocate(std::size_t n) {
6363
if (n < MinAllocSize)
6464
n = MinAllocSize;
65-
return std::allocator<T>().allocate(n);
65+
return static_cast<T*>(::operator new(n * sizeof(T)));
6666
}
6767

68-
TEST_CONSTEXPR_CXX20 void deallocate(T* p, std::size_t n) TEST_NOEXCEPT { std::allocator<T>().deallocate(p, n); }
68+
TEST_CONSTEXPR_CXX20 void deallocate(T* p, std::size_t) TEST_NOEXCEPT { ::operator delete(static_cast<void*>(p)); }
6969

7070
template <typename U>
7171
struct rebind {
@@ -95,10 +95,10 @@ class pow2_allocator {
9595
TEST_CONSTEXPR_CXX20 pow2_allocator(const pow2_allocator<U>&) TEST_NOEXCEPT {}
9696

9797
TEST_NODISCARD TEST_CONSTEXPR_CXX20 T* allocate(std::size_t n) {
98-
return std::allocator<T>().allocate(next_power_of_two(n));
98+
return static_cast<T*>(::operator new(next_power_of_two(n) * sizeof(T)));
9999
}
100100

101-
TEST_CONSTEXPR_CXX20 void deallocate(T* p, std::size_t n) TEST_NOEXCEPT { std::allocator<T>().deallocate(p, n); }
101+
TEST_CONSTEXPR_CXX20 void deallocate(T* p, std::size_t) TEST_NOEXCEPT { ::operator delete(static_cast<void*>(p)); }
102102

103103
private:
104104
TEST_CONSTEXPR_CXX20 std::size_t next_power_of_two(std::size_t n) const {

0 commit comments

Comments
 (0)