77 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410// TODO: Change to XFAIL once https://llvm.org/PR40995 is fixed11// UNSUPPORTED: availability-pmr-missing12 13// test_memory_resource requires RTTI for dynamic_cast14// UNSUPPORTED: no-rtti15 16// <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 to25// 'set_default_resource(...)' and 'new_delete_resource()' if no call26// to 'set_default_resource(...)' has occurred.27// C) 'set_default_resource(...)' returns the previous value of the default28// resource.29// D) 'set_default_resource(T* p)' for a non-null 'p' sets the default resource30// to be 'p'.31// E) 'set_default_resource(null)' sets the default resource to32// 'new_delete_resource()'.33// F) 'get_default_resource' and 'set_default_resource' are noexcept.34 35#include <memory_resource>36#include <cassert>37 38#include "test_std_memory_resource.h"39 40using namespace std::pmr;41 42int main(int, char**) {43 TestResource R;44 { // Test (A) and (B)45 memory_resource* p = get_default_resource();46 assert(p != nullptr);47 assert(p == new_delete_resource());48 assert(p == get_default_resource());49 }50 { // Test (C) and (D)51 memory_resource* expect = &R;52 memory_resource* old = set_default_resource(expect);53 assert(old != nullptr);54 assert(old == new_delete_resource());55 56 memory_resource* p = get_default_resource();57 assert(p != nullptr);58 assert(p == expect);59 assert(p == get_default_resource());60 }61 { // Test (E)62 memory_resource* old = set_default_resource(nullptr);63 assert(old == &R);64 memory_resource* p = get_default_resource();65 assert(p != nullptr);66 assert(p == new_delete_resource());67 assert(p == get_default_resource());68 }69 { // Test (F)70 static_assert(noexcept(get_default_resource()), "get_default_resource() must be noexcept");71 72 static_assert(noexcept(set_default_resource(nullptr)), "set_default_resource() must be noexcept");73 }74 75 return 0;76}77