brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 5bc5b79 Raw
95 lines · cpp
1// RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t -- -- -DGCC2// RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t -- -- -DCLANG3 4namespace std {5class strong_ordering;6 7// Mock how STD defined unspecified parameters for the operators below.8#ifdef CLANG9struct _CmpUnspecifiedParam {10  consteval11  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}12};13 14#define UNSPECIFIED_TYPE _CmpUnspecifiedParam15#endif16 17#ifdef GCC18namespace __cmp_cat {19  struct __unspec {20    constexpr __unspec(__unspec*) noexcept { }21  };22}23 24#define UNSPECIFIED_TYPE __cmp_cat::__unspec25#endif26 27struct strong_ordering {28  signed char value;29 30  friend constexpr bool operator==(strong_ordering v,31                                   UNSPECIFIED_TYPE) noexcept {32    return v.value == 0;33  }34  friend constexpr bool operator<(strong_ordering v,35                                  UNSPECIFIED_TYPE) noexcept {36    return v.value < 0;37  }38  friend constexpr bool operator>(strong_ordering v,39                                  UNSPECIFIED_TYPE) noexcept {40    return v.value > 0;41  }42  friend constexpr bool operator>=(strong_ordering v,43                                   UNSPECIFIED_TYPE) noexcept {44    return v.value >= 0;45  }46  static const strong_ordering equal, greater, less;47};48 49constexpr strong_ordering strong_ordering::equal = {0};50constexpr strong_ordering strong_ordering::greater = {1};51constexpr strong_ordering strong_ordering::less = {-1};52} // namespace std53 54class A {55  int a;56public:57  auto operator<=>(const A &other) const = default;58  // CHECK-FIXES: auto operator<=>(const A &other) const = default;59};60 61void test_cxx_rewritten_binary_ops() {62  A a1, a2;63  bool result;64  // should not change next line to (a1 nullptr a2)65  result = (a1 < a2);66  // CHECK-FIXES: result = (a1 < a2);67  // should not change next line to (a1 nullptr a2)68  result = (a1 >= a2);69  // CHECK-FIXES: result = (a1 >= a2);70  int *ptr = 0;71  // CHECK-FIXES: int *ptr = nullptr;72  result = (a1 > (ptr == 0 ? a1 : a2));73  // CHECK-FIXES: result = (a1 > (ptr == nullptr ? a1 : a2));74  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2));75  // CHECK-FIXES: result = (a1 > ((a1 > (ptr == nullptr ? a1 : a2)) ? a1 : a2));76}77 78void testValidZero() {79  A a1, a2;80  auto result = a1 <=> a2;81  if (result < 0) {}82  // CHECK-FIXES: if (result < 0) {}83}84 85template<class T1, class T2>86struct P {87  T1 x1;88  T2 x2;89  friend auto operator<=>(const P&, const P&) = default;90  // CHECK-FIXES: friend auto operator<=>(const P&, const P&) = default;91};92 93bool foo(P<int,int> x, P<int, int> y) { return x < y; }94// CHECK-FIXES: bool foo(P<int,int> x, P<int, int> y) { return x < y; }95