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 10 11 // Aligned allocation is required by std::experimental::pmr, but it was not provided 12 // before macosx10.13 and as a result we get linker errors when deploying to older than 13 // macosx10.13. 14 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}} 15 16 // <experimental/memory_resource> 17 18 //----------------------------------------------------------------------------- 19 // TESTING memory_resource * get_default_resource() noexcept; 20 // memory_resource * set_default_resource(memory_resource*) noexcept; 21 // 22 // Concerns: 23 // A) 'get_default_resource()' returns a non-null memory_resource pointer. 24 // B) 'get_default_resource()' returns the value set by the last call to 25 // 'set_default_resource(...)' and 'new_delete_resource()' if no call 26 // to 'set_default_resource(...)' has occurred. 27 // C) 'set_default_resource(...)' returns the previous value of the default 28 // resource. 29 // D) 'set_default_resource(T* p)' for a non-null 'p' sets the default resource 30 // to be 'p'. 31 // E) 'set_default_resource(null)' sets the default resource to 32 // 'new_delete_resource()'. 33 // F) 'get_default_resource' and 'set_default_resource' are noexcept. 34 35 36 #include <experimental/memory_resource> 37 #include <cassert> 38 39 #include "test_memory_resource.h" 40 41 #include "test_macros.h" 42 43 using namespace std::experimental::pmr; 44 45 int main(int, char**) { 46 TestResource R; 47 { // Test (A) and (B) 48 memory_resource* p = get_default_resource(); 49 assert(p != nullptr); 50 assert(p == new_delete_resource()); 51 assert(p == get_default_resource()); 52 } 53 { // Test (C) and (D) 54 memory_resource *expect = &R; 55 memory_resource *old = set_default_resource(expect); 56 assert(old != nullptr); 57 assert(old == new_delete_resource()); 58 59 memory_resource *p = get_default_resource(); 60 assert(p != nullptr); 61 assert(p == expect); 62 assert(p == get_default_resource()); 63 } 64 { // Test (E) 65 memory_resource* old = set_default_resource(nullptr); 66 assert(old == &R); 67 memory_resource* p = get_default_resource(); 68 assert(p != nullptr); 69 assert(p == new_delete_resource()); 70 assert(p == get_default_resource()); 71 } 72 { // Test (F) 73 static_assert(noexcept(get_default_resource()), 74 "get_default_resource() must be noexcept"); 75 76 static_assert(noexcept(set_default_resource(nullptr)), 77 "set_default_resource() must be noexcept"); 78 } 79 80 return 0; 81 } 82