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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14
10// TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed
11// UNSUPPORTED: availability-pmr-missing
12
13// <memory_resource>
14
15// class monotonic_buffer_resource
16
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 char buffer[100];
27 auto mono1 = std::pmr::monotonic_buffer_resource(buffer, 0, std::pmr::new_delete_resource());
28 std::pmr::memory_resource& r1 = mono1;
29
30 void* ret = r1.allocate(bytes: 1, alignment: 1);
31 assert(ret != nullptr);
32 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkNewCalledEq(1));
33 }
34 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledEq(1));
35 assert(globalMemCounter.checkOutstandingNewEq(0));
36
37 globalMemCounter.reset();
38 {
39 auto mono1 = std::pmr::monotonic_buffer_resource(nullptr, 0, std::pmr::new_delete_resource());
40 std::pmr::memory_resource& r1 = mono1;
41
42 void* ret = r1.allocate(bytes: 1, alignment: 1);
43 assert(ret != nullptr);
44 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkNewCalledEq(1));
45 }
46 ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkDeleteCalledEq(1));
47 assert(globalMemCounter.checkOutstandingNewEq(0));
48
49 return 0;
50}
51

source code of libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/allocate_from_zero_sized_buffer.pass.cpp