| 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 synchronized_pool_resource |
| 16 |
// class unsynchronized_pool_resource |
| 17 |
|
| 18 |
#include <memory_resource> |
| 19 |
#include <cassert> |
| 20 |
#include <new> |
| 21 |
#include <type_traits> |
| 22 |
|
| 23 |
#include "count_new.h" |
| 24 |
|
| 25 |
class assert_on_compare : public std::pmr::memory_resource { |
| 26 |
void* do_allocate(std::size_t, size_t) override { |
| 27 |
assert(false); |
| 28 |
return nullptr; |
| 29 |
} |
| 30 |
|
| 31 |
void do_deallocate(void*, std::size_t, size_t) override { assert(false); } |
| 32 |
|
| 33 |
bool do_is_equal(const std::pmr::memory_resource&) const noexcept override { |
| 34 |
assert(false); |
| 35 |
return true; |
| 36 |
} |
| 37 |
}; |
| 38 |
|
| 39 |
template <class PoolResource> |
| 40 |
void test() { |
| 41 |
// Same type |
| 42 |
{ |
| 43 |
PoolResource pr1; |
| 44 |
PoolResource pr2; |
| 45 |
assert(pr1 == pr1); |
| 46 |
assert(pr1 != pr2); |
| 47 |
|
| 48 |
std::pmr::memory_resource& mr1 = pr1; |
| 49 |
std::pmr::memory_resource& mr2 = pr2; |
| 50 |
assert(mr1 == mr1); |
| 51 |
assert(mr1 != mr2); |
| 52 |
assert(mr1 == pr1); |
| 53 |
assert(pr1 == mr1); |
| 54 |
assert(mr1 != pr2); |
| 55 |
assert(pr2 != mr1); |
| 56 |
} |
| 57 |
// Different types |
| 58 |
{ |
| 59 |
PoolResource pr1; |
| 60 |
std::pmr::memory_resource& mr1 = pr1; |
| 61 |
assert_on_compare c; |
| 62 |
std::pmr::memory_resource& mr2 = c; |
| 63 |
assert(mr1 != mr2); |
| 64 |
assert(!(mr1 == mr2)); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
int main(int, char**) { |
| 69 |
test<std::pmr::synchronized_pool_resource>(); |
| 70 |
test<std::pmr::unsynchronized_pool_resource>(); |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |