[LoongArch] Supports FP_TO_SINT operation for fp16 (#118303)
[llvm-project.git] / libcxx / test / std / utilities / utility / mem.res / mem.res.global / null_memory_resource.pass.cpp
blobfc8a9e455a4bfa8fb246f87fd54c9c53a79f1664
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 //===----------------------------------------------------------------------===//
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 // <memory_resource>
15 // memory_resource *null_memory_resource()
17 #include <memory_resource>
18 #include <cassert>
19 #include <cstddef> // size_t
20 #include <new>
21 #include <type_traits>
23 #include "count_new.h"
24 #include "test_macros.h"
26 struct assert_on_compare : public std::pmr::memory_resource {
27 void* do_allocate(std::size_t, size_t) override {
28 assert(false);
29 return nullptr;
32 void do_deallocate(void*, std::size_t, size_t) override { assert(false); }
34 bool do_is_equal(const std::pmr::memory_resource&) const noexcept override {
35 assert(false);
36 return true;
40 void test_return() {
41 { ASSERT_SAME_TYPE(decltype(std::pmr::null_memory_resource()), std::pmr::memory_resource*); }
42 // Test that the returned value is not null
43 { assert(std::pmr::null_memory_resource()); }
44 // Test the same value is returned by repeated calls.
45 { assert(std::pmr::null_memory_resource() == std::pmr::null_memory_resource()); }
48 void test_equality() {
49 // Same object
51 std::pmr::memory_resource& r1 = *std::pmr::null_memory_resource();
52 std::pmr::memory_resource& r2 = *std::pmr::null_memory_resource();
53 // check both calls returned the same object
54 assert(&r1 == &r2);
55 // check for proper equality semantics
56 assert(r1 == r2);
57 assert(r2 == r1);
58 assert(!(r1 != r2));
59 assert(!(r2 != r1));
60 // check the is_equal method
61 assert(r1.is_equal(r2));
62 assert(r2.is_equal(r1));
64 // Different types
66 std::pmr::memory_resource& r1 = *std::pmr::null_memory_resource();
67 assert_on_compare c;
68 std::pmr::memory_resource& r2 = c;
69 assert(r1 != r2);
70 assert(!(r1 == r2));
71 assert(!r1.is_equal(r2));
75 void test_allocate() {
76 #ifndef TEST_HAS_NO_EXCEPTIONS
77 DisableAllocationGuard g; // null_memory_resource shouldn't allocate.
78 try {
79 (void)std::pmr::null_memory_resource()->allocate(1);
80 assert(false);
81 } catch (std::bad_alloc const&) {
82 // do nothing
83 } catch (...) {
84 assert(false);
86 #endif
89 void test_deallocate() {
90 globalMemCounter.reset();
92 int x = 42;
93 std::pmr::null_memory_resource()->deallocate(&x, 0);
95 assert(globalMemCounter.checkDeleteCalledEq(0));
96 assert(globalMemCounter.checkDeleteArrayCalledEq(0));
99 int main(int, char**) {
100 test_return();
101 test_equality();
102 test_allocate();
103 test_deallocate();
105 return 0;