Debian Codegraph @

libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.ctor/default.pass.cpp

raw
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 // test_memory_resource requires RTTI for dynamic_cast
14 // UNSUPPORTED: no-rtti
15
16 // <memory_resource>
17
18 // template <class T> class polymorphic_allocator
19
20 // polymorphic_allocator<T>::polymorphic_allocator() noexcept
21
22 #include <memory_resource>
23 #include <cassert>
24 #include <type_traits>
25
26 #include "test_std_memory_resource.h"
27
28 int main(int, char**) {
29 {
30 static_assert(std::is_nothrow_default_constructible<std::pmr::polymorphic_allocator<void>>::value,
31 "Must me nothrow default constructible");
32 }
33 {
34 // test that the allocator gets its resource from get_default_resource
35 TestResource R1(42);
36 std::pmr::set_default_resource(&R1);
37
38 typedef std::pmr::polymorphic_allocator<void> A;
39 A const a;
40 assert(a.resource() == &R1);
41
42 std::pmr::set_default_resource(nullptr);
43 A const a2;
44 assert(a.resource() == &R1);
45 assert(a2.resource() == std::pmr::new_delete_resource());
46 }
47
48 return 0;
49 }