brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 3f28120 Raw
53 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 unsynchronized_pool_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  globalMemCounter.reset();25  {26    auto unsync1                  = std::pmr::unsynchronized_pool_resource(std::pmr::new_delete_resource());27    std::pmr::memory_resource& r1 = unsync1;28 29    void* ret = r1.allocate(50);30    assert(ret);31    ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkNewCalledGreaterThan(0));32    assert(globalMemCounter.checkDeleteCalledEq(0));33 34    r1.deallocate(ret, 50);35    unsync1.release();36    ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledGreaterThan(0));37    assert(globalMemCounter.checkOutstandingNewEq(0));38 39    globalMemCounter.reset();40 41    ret = r1.allocate(500);42    assert(ret);43    ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkNewCalledGreaterThan(0));44    assert(globalMemCounter.checkDeleteCalledEq(0));45 46    // Check that the destructor calls release()47  }48  ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledGreaterThan(0));49  assert(globalMemCounter.checkOutstandingNewEq(0));50 51  return 0;52}53