1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 11 12 // <compare> 13 14 // class weak_equality 15 16 17 #include <compare> 18 #include <cassert> 19 #include "test_macros.h" 20 21 const volatile void* volatile sink; 22 23 void test_static_members() { 24 DoNotOptimize(&std::weak_equality::equivalent); 25 DoNotOptimize(&std::weak_equality::nonequivalent); 26 } 27 28 void test_signatures() { 29 auto& Eq = std::weak_equality::equivalent; 30 31 ASSERT_NOEXCEPT(Eq == 0); 32 ASSERT_NOEXCEPT(0 == Eq); 33 ASSERT_NOEXCEPT(Eq != 0); 34 ASSERT_NOEXCEPT(0 != Eq); 35 #ifndef TEST_HAS_NO_SPACESHIP_OPERATOR 36 ASSERT_NOEXCEPT(0 <=> Eq); 37 ASSERT_NOEXCEPT(Eq <=> 0); 38 ASSERT_SAME_TYPE(decltype(Eq <=> 0), std::weak_equality); 39 ASSERT_SAME_TYPE(decltype(0 <=> Eq), std::weak_equality); 40 #endif 41 } 42 43 constexpr bool test_constexpr() { 44 auto& Eq = std::weak_equality::equivalent; 45 auto& NEq = std::weak_equality::nonequivalent; 46 assert((Eq == 0) == true); 47 assert((0 == Eq) == true); 48 assert((NEq == 0) == false); 49 assert((0 == NEq) == false); 50 51 assert((Eq != 0) == false); 52 assert((0 != Eq) == false); 53 assert((NEq != 0) == true); 54 assert((0 != NEq) == true); 55 56 #ifndef TEST_HAS_NO_SPACESHIP_OPERATOR 57 std::weak_equality res = (Eq <=> 0); 58 ((void)res); 59 res = (0 <=> Eq); 60 ((void)res); 61 #endif 62 63 return true; 64 } 65 66 int main() { 67 test_static_members(); 68 test_signatures(); 69 static_assert(test_constexpr(), "constexpr test failed"); 70 } 71