//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // shared_ptr // template // bool operator==(const shared_ptr& x, nullptr_t) noexcept; // template // bool operator==(nullptr_t, const shared_ptr& y) noexcept; // template // bool operator!=(const shared_ptr& x, nullptr_t) noexcept; // template // bool operator!=(nullptr_t, const shared_ptr& y) noexcept; // template // bool operator<(const shared_ptr& x, nullptr_t) noexcept; // template // bool operator<(nullptr_t, const shared_ptr& y) noexcept; // template // bool operator<=(const shared_ptr& x, nullptr_t) noexcept; // template // bool operator<=(nullptr_t, const shared_ptr& y) noexcept; // template // bool operator>(const shared_ptr& x, nullptr_t) noexcept; // template // bool operator>(nullptr_t, const shared_ptr& y) noexcept; // template // bool operator>=(const shared_ptr& x, nullptr_t) noexcept; // template // bool operator>=(nullptr_t, const shared_ptr& y) noexcept; // template // strong_ordering operator<=>(shared_ptr const& x, nullptr_t) noexcept; // C++20 #include #include #include #include "test_macros.h" #include "test_comparisons.h" void do_nothing(int*) {} int main(int, char**) { AssertComparisonsAreNoexcept, nullptr_t>(); AssertComparisonsAreNoexcept >(); AssertComparisonsReturnBool, nullptr_t>(); AssertComparisonsReturnBool >(); #if TEST_STD_VER >= 20 AssertOrderAreNoexcept>(); AssertOrderReturn>(); #endif const std::shared_ptr p1(new int(1)); assert(!(p1 == nullptr)); assert(!(nullptr == p1)); assert(!(p1 < nullptr)); assert((nullptr < p1)); assert(!(p1 <= nullptr)); assert((nullptr <= p1)); assert((p1 > nullptr)); assert(!(nullptr > p1)); assert((p1 >= nullptr)); assert(!(nullptr >= p1)); #if TEST_STD_VER >= 20 assert((nullptr <=> p1) == std::strong_ordering::less); assert((p1 <=> nullptr) == std::strong_ordering::greater); #endif const std::shared_ptr p2; assert((p2 == nullptr)); assert((nullptr == p2)); assert(!(p2 < nullptr)); assert(!(nullptr < p2)); assert((p2 <= nullptr)); assert((nullptr <= p2)); assert(!(p2 > nullptr)); assert(!(nullptr > p2)); assert((p2 >= nullptr)); assert((nullptr >= p2)); #if TEST_STD_VER >= 20 assert((p2 <=> nullptr) == std::strong_ordering::equivalent); assert((nullptr <=> p2) == std::strong_ordering::equivalent); #endif #if TEST_STD_VER >= 17 const std::shared_ptr p3(new int[1]); assert(!(p3 == nullptr)); assert(!(nullptr == p3)); assert(!(p3 < nullptr)); assert((nullptr < p3)); assert(!(p3 <= nullptr)); assert((nullptr <= p3)); assert((p3 > nullptr)); assert(!(nullptr > p3)); assert((p3 >= nullptr)); assert(!(nullptr >= p3)); # if TEST_STD_VER >= 20 assert((p3 <=> nullptr) == std::strong_ordering::greater); assert((nullptr <=> p3) == std::strong_ordering::less); # endif const std::shared_ptr p4; assert((p4 == nullptr)); assert((nullptr == p4)); assert(!(p4 < nullptr)); assert(!(nullptr < p4)); assert((p4 <= nullptr)); assert((nullptr <= p4)); assert(!(p4 > nullptr)); assert(!(nullptr > p4)); assert((p4 >= nullptr)); assert((nullptr >= p4)); # if TEST_STD_VER >= 20 assert((p4 <=> nullptr) == std::strong_ordering::equivalent); assert((nullptr <=> p4) == std::strong_ordering::equivalent); # endif #endif return 0; }