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// template <class T> class polymorphic_allocator
16
17// memory_resource *
18// polymorphic_allocator<T>::resource() const
19
20#include <memory_resource>
21#include <cassert>
22
23#include "test_macros.h"
24
25int main(int, char**) {
26 typedef std::pmr::polymorphic_allocator<void> A;
27 {
28 A const a;
29 ASSERT_SAME_TYPE(decltype(a.resource()), std::pmr::memory_resource*);
30 }
31 {
32 std::pmr::memory_resource* mptr = (std::pmr::memory_resource*)42;
33 A const a(mptr);
34 assert(a.resource() == mptr);
35 }
36 {
37 A const a(nullptr);
38 assert(a.resource() == nullptr);
39 assert(a.resource() == nullptr);
40 }
41 {
42 A const a;
43 assert(a.resource() == std::pmr::get_default_resource());
44 }
45 {
46 std::pmr::memory_resource* mptr = (std::pmr::memory_resource*)42;
47 std::pmr::set_default_resource(mptr);
48 A const a;
49 assert(a.resource() == mptr);
50 assert(a.resource() == std::pmr::get_default_resource());
51 }
52
53 return 0;
54}
55

source code of libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/resource.pass.cpp