//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Make sure the size we allocate and deallocate match. See https://github.com/llvm/llvm-project/pull/90292. #include #include #include #include #include #include "test_macros.h" static std::uint64_t allocated_; static std::uint64_t deallocated_; template struct test_alloc { typedef Sz size_type; typedef typename std::make_signed::type difference_type; typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef typename std::add_lvalue_reference::type reference; typedef typename std::add_lvalue_reference::type const_reference; template struct rebind { typedef test_alloc other; }; TEST_CONSTEXPR test_alloc() TEST_NOEXCEPT {} template TEST_CONSTEXPR test_alloc(const test_alloc&) TEST_NOEXCEPT {} pointer allocate(size_type n, const void* = nullptr) { allocated_ += n; return std::allocator().allocate(static_cast(n)); } void deallocate(pointer p, size_type s) { deallocated_ += s; std::allocator().deallocate(p, static_cast(s)); } template friend TEST_CONSTEXPR bool operator==(const test_alloc&, const test_alloc&) TEST_NOEXCEPT { return true; } #if TEST_STD_VER < 20 template friend TEST_CONSTEXPR bool operator!=(const test_alloc&, const test_alloc&) TEST_NOEXCEPT { return false; } #endif }; template void test() { for (unsigned int i = 1; i < 1000; ++i) { { std::basic_string, test_alloc > s(i, 't'); (void)s; } assert(allocated_ == deallocated_); } } int main(int, char**) { test(); test(); test(); return 0; }