cmp.weakeq.pass.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
  10. // <compare>
  11. // class weak_equality
  12. #include <compare>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. const volatile void* volatile sink;
  16. void test_static_members() {
  17. DoNotOptimize(&std::weak_equality::equivalent);
  18. DoNotOptimize(&std::weak_equality::nonequivalent);
  19. }
  20. void test_signatures() {
  21. auto& Eq = std::weak_equality::equivalent;
  22. ASSERT_NOEXCEPT(Eq == 0);
  23. ASSERT_NOEXCEPT(0 == Eq);
  24. ASSERT_NOEXCEPT(Eq != 0);
  25. ASSERT_NOEXCEPT(0 != Eq);
  26. #ifndef TEST_HAS_NO_SPACESHIP_OPERATOR
  27. ASSERT_NOEXCEPT(0 <=> Eq);
  28. ASSERT_NOEXCEPT(Eq <=> 0);
  29. ASSERT_SAME_TYPE(decltype(Eq <=> 0), std::weak_equality);
  30. ASSERT_SAME_TYPE(decltype(0 <=> Eq), std::weak_equality);
  31. #endif
  32. }
  33. constexpr bool test_constexpr() {
  34. auto& Eq = std::weak_equality::equivalent;
  35. auto& NEq = std::weak_equality::nonequivalent;
  36. assert((Eq == 0) == true);
  37. assert((0 == Eq) == true);
  38. assert((NEq == 0) == false);
  39. assert((0 == NEq) == false);
  40. assert((Eq != 0) == false);
  41. assert((0 != Eq) == false);
  42. assert((NEq != 0) == true);
  43. assert((0 != NEq) == true);
  44. #ifndef TEST_HAS_NO_SPACESHIP_OPERATOR
  45. std::weak_equality res = (Eq <=> 0);
  46. ((void)res);
  47. res = (0 <=> Eq);
  48. ((void)res);
  49. #endif
  50. return true;
  51. }
  52. int main() {
  53. test_static_members();
  54. test_signatures();
  55. static_assert(test_constexpr(), "constexpr test failed");
  56. }