//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// // // unique_ptr // template // constexpr bool operator==(const unique_ptr& x, nullptr_t) noexcept; // constexpr since C++23 // template // bool operator==(nullptr_t, const unique_ptr& y) noexcept; // removed in C++20 // template // bool operator!=(const unique_ptr& x, nullptr_t) noexcept; // removed in C++20 // template // bool operator!=(nullptr_t, const unique_ptr& y) noexcept; // removed in C++20 // template // constexpr bool operator<(const unique_ptr& x, nullptr_t); // constexpr since C++23 // template // constexpr bool operator<(nullptr_t, const unique_ptr& y); // constexpr since C++23 // template // constexpr bool operator<=(const unique_ptr& x, nullptr_t); // constexpr since C++23 // template // constexpr bool operator<=(nullptr_t, const unique_ptr& y); // constexpr since C++23 // template // constexpr bool operator>(const unique_ptr& x, nullptr_t); // constexpr since C++23 // template // constexpr bool operator>(nullptr_t, const unique_ptr& y); // constexpr since C++23 // template // constexpr bool operator>=(const unique_ptr& x, nullptr_t); // constexpr since C++23 // template // constexpr bool operator>=(nullptr_t, const unique_ptr& y); // constexpr since C++23 // template // requires three_way_comparable::pointer> // constexpr compare_three_way_result_t::pointer> // operator<=>(const unique_ptr& x, nullptr_t); // C++20 #include #include #include #include "test_macros.h" #include "test_comparisons.h" TEST_CONSTEXPR_CXX23 bool test() { if (!TEST_IS_CONSTANT_EVALUATED) { AssertEqualityAreNoexcept, nullptr_t>(); AssertEqualityAreNoexcept >(); AssertComparisonsReturnBool, nullptr_t>(); AssertComparisonsReturnBool >(); #if TEST_STD_VER >= 20 AssertOrderReturn, nullptr_t>(); AssertOrderReturn>(); #endif } const std::unique_ptr p1(new int(1)); assert(!(p1 == nullptr)); assert(!(nullptr == p1)); // A pointer to allocated storage and a nullptr can't be compared at compile-time if (!TEST_IS_CONSTANT_EVALUATED) { 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((p1 <=> nullptr) == std::strong_ordering::greater); assert((nullptr <=> p1) == std::strong_ordering::less); #endif } const std::unique_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 const std::unique_ptr p3(new int[1]); assert(!(p3 == nullptr)); assert(!(nullptr == p3)); // A pointer to allocated storage and a nullptr can't be compared at compile-time if (!TEST_IS_CONSTANT_EVALUATED) { 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((nullptr <=> p3) == std::strong_ordering::less); assert((p3 <=> nullptr) == std::strong_ordering::greater); #endif } const std::unique_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 return true; } int main(int, char**) { test(); #if TEST_STD_VER >= 23 static_assert(test()); #endif return 0; }