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 //===----------------------------------------------------------------------===//
14 // bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
16 // bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
18 // bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
20 // bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
22 // bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
24 // bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
26 // bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
28 // bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
30 // bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
32 // bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
34 // bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
36 // bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
38 // strong_ordering operator<=>(shared_ptr<T> const& x, nullptr_t) noexcept; // C++20
44 #include "test_macros.h"
45 #include "test_comparisons.h"
47 void do_nothing(int*) {}
51 AssertComparisonsAreNoexcept
<std::shared_ptr
<int>, nullptr_t
>();
52 AssertComparisonsAreNoexcept
<nullptr_t
, std::shared_ptr
<int> >();
53 AssertComparisonsReturnBool
<std::shared_ptr
<int>, nullptr_t
>();
54 AssertComparisonsReturnBool
<nullptr_t
, std::shared_ptr
<int> >();
55 #if TEST_STD_VER >= 20
56 AssertOrderAreNoexcept
<std::shared_ptr
<int>>();
57 AssertOrderReturn
<std::strong_ordering
, std::shared_ptr
<int>>();
60 const std::shared_ptr
<int> p1(new int(1));
61 assert(!(p1
== nullptr));
62 assert(!(nullptr == p1
));
63 assert(!(p1
< nullptr));
64 assert((nullptr < p1
));
65 assert(!(p1
<= nullptr));
66 assert((nullptr <= p1
));
67 assert((p1
> nullptr));
68 assert(!(nullptr > p1
));
69 assert((p1
>= nullptr));
70 assert(!(nullptr >= p1
));
71 #if TEST_STD_VER >= 20
72 assert((nullptr <=> p1
) == std::strong_ordering::less
);
73 assert((p1
<=> nullptr) == std::strong_ordering::greater
);
76 const std::shared_ptr
<int> p2
;
77 assert((p2
== nullptr));
78 assert((nullptr == p2
));
79 assert(!(p2
< nullptr));
80 assert(!(nullptr < p2
));
81 assert((p2
<= nullptr));
82 assert((nullptr <= p2
));
83 assert(!(p2
> nullptr));
84 assert(!(nullptr > p2
));
85 assert((p2
>= nullptr));
86 assert((nullptr >= p2
));
87 #if TEST_STD_VER >= 20
88 assert((p2
<=> nullptr) == std::strong_ordering::equivalent
);
89 assert((nullptr <=> p2
) == std::strong_ordering::equivalent
);
92 #if TEST_STD_VER >= 17
93 const std::shared_ptr
<int[]> p3(new int[1]);
94 assert(!(p3
== nullptr));
95 assert(!(nullptr == p3
));
96 assert(!(p3
< nullptr));
97 assert((nullptr < p3
));
98 assert(!(p3
<= nullptr));
99 assert((nullptr <= p3
));
100 assert((p3
> nullptr));
101 assert(!(nullptr > p3
));
102 assert((p3
>= nullptr));
103 assert(!(nullptr >= p3
));
104 # if TEST_STD_VER >= 20
105 assert((p3
<=> nullptr) == std::strong_ordering::greater
);
106 assert((nullptr <=> p3
) == std::strong_ordering::less
);
109 const std::shared_ptr
<int[]> p4
;
110 assert((p4
== nullptr));
111 assert((nullptr == p4
));
112 assert(!(p4
< nullptr));
113 assert(!(nullptr < p4
));
114 assert((p4
<= nullptr));
115 assert((nullptr <= p4
));
116 assert(!(p4
> nullptr));
117 assert(!(nullptr > p4
));
118 assert((p4
>= nullptr));
119 assert((nullptr >= p4
));
120 # if TEST_STD_VER >= 20
121 assert((p4
<=> nullptr) == std::strong_ordering::equivalent
);
122 assert((nullptr <=> p4
) == std::strong_ordering::equivalent
);