1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
13 // test_memory_resource requires RTTI for dynamic_cast
14 // UNSUPPORTED: no-rtti
18 //-----------------------------------------------------------------------------
19 // TESTING memory_resource * get_default_resource() noexcept;
20 // memory_resource * set_default_resource(memory_resource*) noexcept;
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
29 // D) 'set_default_resource(T* p)' for a non-null 'p' sets the default resource
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.
35 #include <memory_resource>
38 #include "test_std_memory_resource.h"
40 using namespace std::pmr
;
42 int main(int, char**) {
45 memory_resource
* p
= get_default_resource();
47 assert(p
== new_delete_resource());
48 assert(p
== get_default_resource());
51 memory_resource
* expect
= &R
;
52 memory_resource
* old
= set_default_resource(expect
);
53 assert(old
!= nullptr);
54 assert(old
== new_delete_resource());
56 memory_resource
* p
= get_default_resource();
59 assert(p
== get_default_resource());
62 memory_resource
* old
= set_default_resource(nullptr);
64 memory_resource
* p
= get_default_resource();
66 assert(p
== new_delete_resource());
67 assert(p
== get_default_resource());
70 static_assert(noexcept(get_default_resource()), "get_default_resource() must be noexcept");
72 static_assert(noexcept(set_default_resource(nullptr)), "set_default_resource() must be noexcept");