60 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410// TODO: Change to XFAIL once https://llvm.org/PR40995 is fixed11// UNSUPPORTED: availability-pmr-missing12 13// <memory_resource>14 15// class monotonic_buffer_resource16 17#include <memory_resource>18#include <cassert>19 20#include "count_new.h"21#include "test_macros.h"22 23int main(int, char**) {24 {25 globalMemCounter.reset();26 27 auto mono1 = std::pmr::monotonic_buffer_resource(std::pmr::new_delete_resource());28 std::pmr::memory_resource& r1 = mono1;29 30 void* ret = r1.allocate(50);31 assert(ret);32 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkNewCalledGreaterThan(0));33 assert(globalMemCounter.checkDeleteCalledEq(0));34 35 // mem.res.monotonic.buffer 1.236 // A call to deallocate has no effect, thus the amount of memory37 // consumed increases monotonically until the resource is destroyed.38 // Check that deallocate is a no-op39 r1.deallocate(ret, 50);40 assert(globalMemCounter.checkDeleteCalledEq(0));41 42 mono1.release();43 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledEq(1));44 assert(globalMemCounter.checkOutstandingNewEq(0));45 46 globalMemCounter.reset();47 48 ret = r1.allocate(500);49 assert(ret);50 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkNewCalledGreaterThan(0));51 assert(globalMemCounter.checkDeleteCalledEq(0));52 53 // Check that the destructor calls release()54 }55 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledEq(1));56 assert(globalMemCounter.checkOutstandingNewEq(0));57 58 return 0;59}60