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 | // <memory> |
10 | |
11 | // shared_ptr |
12 | |
13 | // template <class T> |
14 | // bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; |
15 | // template <class T> |
16 | // bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; |
17 | // template <class T> |
18 | // bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; |
19 | // template <class T> |
20 | // bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; |
21 | // template <class T> |
22 | // bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; |
23 | // template <class T> |
24 | // bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; |
25 | // template <class T> |
26 | // bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; |
27 | // template <class T> |
28 | // bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; |
29 | // template <class T> |
30 | // bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; |
31 | // template <class T> |
32 | // bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; |
33 | // template <class T> |
34 | // bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; |
35 | // template <class T> |
36 | // bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; |
37 | // template<class T> |
38 | // strong_ordering operator<=>(shared_ptr<T> const& x, nullptr_t) noexcept; // C++20 |
39 | |
40 | #include <memory> |
41 | #include <cassert> |
42 | |
43 | #include "test_macros.h" |
44 | #include "test_comparisons.h" |
45 | |
46 | void do_nothing(int*) {} |
47 | |
48 | int main(int, char**) |
49 | { |
50 | AssertComparisonsAreNoexcept<std::shared_ptr<int>, nullptr_t>(); |
51 | AssertComparisonsAreNoexcept<nullptr_t, std::shared_ptr<int> >(); |
52 | AssertComparisonsReturnBool<std::shared_ptr<int>, nullptr_t>(); |
53 | AssertComparisonsReturnBool<nullptr_t, std::shared_ptr<int> >(); |
54 | #if TEST_STD_VER >= 20 |
55 | AssertOrderAreNoexcept<std::shared_ptr<int>>(); |
56 | AssertOrderReturn<std::strong_ordering, std::shared_ptr<int>>(); |
57 | #endif |
58 | |
59 | const std::shared_ptr<int> p1(new int(1)); |
60 | assert(!(p1 == nullptr)); |
61 | assert(!(nullptr == p1)); |
62 | assert(!(p1 < nullptr)); |
63 | assert((nullptr < p1)); |
64 | assert(!(p1 <= nullptr)); |
65 | assert((nullptr <= p1)); |
66 | assert((p1 > nullptr)); |
67 | assert(!(nullptr > p1)); |
68 | assert((p1 >= nullptr)); |
69 | assert(!(nullptr >= p1)); |
70 | #if TEST_STD_VER >= 20 |
71 | assert((nullptr <=> p1) == std::strong_ordering::less); |
72 | assert((p1 <=> nullptr) == std::strong_ordering::greater); |
73 | #endif |
74 | |
75 | const std::shared_ptr<int> p2; |
76 | assert((p2 == nullptr)); |
77 | assert((nullptr == p2)); |
78 | assert(!(p2 < nullptr)); |
79 | assert(!(nullptr < p2)); |
80 | assert((p2 <= nullptr)); |
81 | assert((nullptr <= p2)); |
82 | assert(!(p2 > nullptr)); |
83 | assert(!(nullptr > p2)); |
84 | assert((p2 >= nullptr)); |
85 | assert((nullptr >= p2)); |
86 | #if TEST_STD_VER >= 20 |
87 | assert((p2 <=> nullptr) == std::strong_ordering::equivalent); |
88 | assert((nullptr <=> p2) == std::strong_ordering::equivalent); |
89 | #endif |
90 | |
91 | #if TEST_STD_VER >= 17 |
92 | const std::shared_ptr<int[]> p3(new int[1]); |
93 | assert(!(p3 == nullptr)); |
94 | assert(!(nullptr == p3)); |
95 | assert(!(p3 < nullptr)); |
96 | assert((nullptr < p3)); |
97 | assert(!(p3 <= nullptr)); |
98 | assert((nullptr <= p3)); |
99 | assert((p3 > nullptr)); |
100 | assert(!(nullptr > p3)); |
101 | assert((p3 >= nullptr)); |
102 | assert(!(nullptr >= p3)); |
103 | # if TEST_STD_VER >= 20 |
104 | assert((p3 <=> nullptr) == std::strong_ordering::greater); |
105 | assert((nullptr <=> p3) == std::strong_ordering::less); |
106 | # endif |
107 | |
108 | const std::shared_ptr<int[]> p4; |
109 | assert((p4 == nullptr)); |
110 | assert((nullptr == p4)); |
111 | assert(!(p4 < nullptr)); |
112 | assert(!(nullptr < p4)); |
113 | assert((p4 <= nullptr)); |
114 | assert((nullptr <= p4)); |
115 | assert(!(p4 > nullptr)); |
116 | assert(!(nullptr > p4)); |
117 | assert((p4 >= nullptr)); |
118 | assert((nullptr >= p4)); |
119 | # if TEST_STD_VER >= 20 |
120 | assert((p4 <=> nullptr) == std::strong_ordering::equivalent); |
121 | assert((nullptr <=> p4) == std::strong_ordering::equivalent); |
122 | # endif |
123 | #endif |
124 | |
125 | return 0; |
126 | } |
127 | |