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