| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s |
| 2 |
|
| 3 |
static_assert(!__builtin_lt_synthesizes_from_spaceship()); // expected-error {{expected a type}} |
| 4 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(int)); // expected-error {{type trait requires 2 arguments; have 1 argument}} |
| 5 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(int, int, int)); // expected-error {{type trait requires 2 arguments; have 3 argument}} |
| 6 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(int, 0)); // expected-error {{expected a type}} |
| 7 |
|
| 8 |
static_assert(!__builtin_le_synthesizes_from_spaceship()); // expected-error {{expected a type}} |
| 9 |
static_assert(!__builtin_le_synthesizes_from_spaceship(int)); // expected-error {{type trait requires 2 arguments; have 1 argument}} |
| 10 |
static_assert(!__builtin_le_synthesizes_from_spaceship(int, int, int)); // expected-error {{type trait requires 2 arguments; have 3 argument}} |
| 11 |
static_assert(!__builtin_le_synthesizes_from_spaceship(int, 0)); // expected-error {{expected a type}} |
| 12 |
|
| 13 |
static_assert(!__builtin_gt_synthesizes_from_spaceship()); // expected-error {{expected a type}} |
| 14 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(int)); // expected-error {{type trait requires 2 arguments; have 1 argument}} |
| 15 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(int, int, int)); // expected-error {{type trait requires 2 arguments; have 3 argument}} |
| 16 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(int, 0)); // expected-error {{expected a type}} |
| 17 |
|
| 18 |
static_assert(!__builtin_ge_synthesizes_from_spaceship()); // expected-error {{expected a type}} |
| 19 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(int)); // expected-error {{type trait requires 2 arguments; have 1 argument}} |
| 20 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(int, int, int)); // expected-error {{type trait requires 2 arguments; have 3 argument}} |
| 21 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(int, 0)); // expected-error {{expected a type}} |
| 22 |
|
| 23 |
namespace std { |
| 24 |
struct strong_ordering { |
| 25 |
int n; |
| 26 |
constexpr operator int() const { return n; } |
| 27 |
static const strong_ordering less, equal, greater; |
| 28 |
}; |
| 29 |
constexpr strong_ordering strong_ordering::less = {-1}; |
| 30 |
constexpr strong_ordering strong_ordering::equal = {0}; |
| 31 |
constexpr strong_ordering strong_ordering::greater = {1}; |
| 32 |
} |
| 33 |
|
| 34 |
struct DefaultSpaceship { |
| 35 |
friend auto operator<=>(DefaultSpaceship, DefaultSpaceship) = default; |
| 36 |
}; |
| 37 |
|
| 38 |
static_assert(__builtin_lt_synthesizes_from_spaceship(const DefaultSpaceship&, const DefaultSpaceship&)); |
| 39 |
static_assert(__builtin_le_synthesizes_from_spaceship(const DefaultSpaceship&, const DefaultSpaceship&)); |
| 40 |
static_assert(__builtin_gt_synthesizes_from_spaceship(const DefaultSpaceship&, const DefaultSpaceship&)); |
| 41 |
static_assert(__builtin_ge_synthesizes_from_spaceship(const DefaultSpaceship&, const DefaultSpaceship&)); |
| 42 |
|
| 43 |
struct CustomSpaceship { |
| 44 |
int i; |
| 45 |
|
| 46 |
friend auto operator<=>(CustomSpaceship lhs, CustomSpaceship rhs) { |
| 47 |
return rhs.i <=> lhs.i; |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
static_assert(__builtin_lt_synthesizes_from_spaceship(const CustomSpaceship&, const CustomSpaceship&)); |
| 52 |
static_assert(__builtin_le_synthesizes_from_spaceship(const CustomSpaceship&, const CustomSpaceship&)); |
| 53 |
static_assert(__builtin_gt_synthesizes_from_spaceship(const CustomSpaceship&, const CustomSpaceship&)); |
| 54 |
static_assert(__builtin_ge_synthesizes_from_spaceship(const CustomSpaceship&, const CustomSpaceship&)); |
| 55 |
|
| 56 |
struct CustomLT { |
| 57 |
int i; |
| 58 |
|
| 59 |
friend auto operator<(CustomLT lhs, CustomLT rhs) { |
| 60 |
return rhs.i < lhs.i; |
| 61 |
} |
| 62 |
}; |
| 63 |
|
| 64 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(const CustomLT&, const CustomLT&)); |
| 65 |
static_assert(!__builtin_le_synthesizes_from_spaceship(const CustomLT&, const CustomLT&)); |
| 66 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(const CustomLT&, const CustomLT&)); |
| 67 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(const CustomLT&, const CustomLT&)); |
| 68 |
|
| 69 |
struct CustomLE { |
| 70 |
int i; |
| 71 |
|
| 72 |
friend auto operator<=(CustomLE lhs, CustomLE rhs) { |
| 73 |
return rhs.i < lhs.i; |
| 74 |
} |
| 75 |
}; |
| 76 |
|
| 77 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(const CustomLE&, const CustomLE&)); |
| 78 |
static_assert(!__builtin_le_synthesizes_from_spaceship(const CustomLE&, const CustomLE&)); |
| 79 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(const CustomLE&, const CustomLE&)); |
| 80 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(const CustomLE&, const CustomLE&)); |
| 81 |
|
| 82 |
struct CustomGT { |
| 83 |
int i; |
| 84 |
|
| 85 |
friend auto operator>(CustomGT lhs, CustomGT rhs) { |
| 86 |
return rhs.i < lhs.i; |
| 87 |
} |
| 88 |
}; |
| 89 |
|
| 90 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(const CustomGT&, const CustomGT&)); |
| 91 |
static_assert(!__builtin_le_synthesizes_from_spaceship(const CustomGT&, const CustomGT&)); |
| 92 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(const CustomGT&, const CustomGT&)); |
| 93 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(const CustomGT&, const CustomGT&)); |
| 94 |
|
| 95 |
struct CustomGE { |
| 96 |
int i; |
| 97 |
|
| 98 |
friend auto operator>=(CustomGE lhs, CustomGE rhs) { |
| 99 |
return rhs.i < lhs.i; |
| 100 |
} |
| 101 |
}; |
| 102 |
|
| 103 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(const CustomGE&, const CustomGE&)); |
| 104 |
static_assert(!__builtin_le_synthesizes_from_spaceship(const CustomGE&, const CustomGE&)); |
| 105 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(const CustomGE&, const CustomGE&)); |
| 106 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(const CustomGE&, const CustomGE&)); |
| 107 |
|
| 108 |
struct CustomLTAndSpaceship { |
| 109 |
int i; |
| 110 |
|
| 111 |
friend auto operator<=>(CustomLTAndSpaceship lhs, CustomLTAndSpaceship rhs) { |
| 112 |
return rhs.i <=> lhs.i; |
| 113 |
} |
| 114 |
|
| 115 |
friend auto operator<(CustomLTAndSpaceship lhs, CustomLTAndSpaceship rhs) { |
| 116 |
return rhs.i < lhs.i; |
| 117 |
} |
| 118 |
}; |
| 119 |
|
| 120 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(const CustomLTAndSpaceship&, const CustomLTAndSpaceship&)); |
| 121 |
static_assert(__builtin_le_synthesizes_from_spaceship(const CustomLTAndSpaceship&, const CustomLTAndSpaceship&)); |
| 122 |
static_assert(__builtin_gt_synthesizes_from_spaceship(const CustomLTAndSpaceship&, const CustomLTAndSpaceship&)); |
| 123 |
static_assert(__builtin_ge_synthesizes_from_spaceship(const CustomLTAndSpaceship&, const CustomLTAndSpaceship&)); |
| 124 |
|
| 125 |
struct CustomLEAndSpaceship { |
| 126 |
int i; |
| 127 |
|
| 128 |
friend auto operator<=>(CustomLEAndSpaceship lhs, CustomLEAndSpaceship rhs) { |
| 129 |
return rhs.i <=> lhs.i; |
| 130 |
} |
| 131 |
|
| 132 |
friend auto operator<=(CustomLEAndSpaceship lhs, CustomLEAndSpaceship rhs) { |
| 133 |
return rhs.i < lhs.i; |
| 134 |
} |
| 135 |
}; |
| 136 |
|
| 137 |
static_assert(__builtin_lt_synthesizes_from_spaceship(const CustomLEAndSpaceship&, const CustomLEAndSpaceship&)); |
| 138 |
static_assert(!__builtin_le_synthesizes_from_spaceship(const CustomLEAndSpaceship&, const CustomLEAndSpaceship&)); |
| 139 |
static_assert(__builtin_gt_synthesizes_from_spaceship(const CustomLEAndSpaceship&, const CustomLEAndSpaceship&)); |
| 140 |
static_assert(__builtin_ge_synthesizes_from_spaceship(const CustomLEAndSpaceship&, const CustomLEAndSpaceship&)); |
| 141 |
|
| 142 |
struct CustomGTAndSpaceship { |
| 143 |
int i; |
| 144 |
|
| 145 |
friend auto operator<=>(CustomGTAndSpaceship lhs, CustomGTAndSpaceship rhs) { |
| 146 |
return rhs.i <=> lhs.i; |
| 147 |
} |
| 148 |
|
| 149 |
friend auto operator>(CustomGTAndSpaceship lhs, CustomGTAndSpaceship rhs) { |
| 150 |
return rhs.i < lhs.i; |
| 151 |
} |
| 152 |
}; |
| 153 |
|
| 154 |
static_assert(__builtin_lt_synthesizes_from_spaceship(const CustomGTAndSpaceship&, const CustomGTAndSpaceship&)); |
| 155 |
static_assert(__builtin_le_synthesizes_from_spaceship(const CustomGTAndSpaceship&, const CustomGTAndSpaceship&)); |
| 156 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(const CustomGTAndSpaceship&, const CustomGTAndSpaceship&)); |
| 157 |
static_assert(__builtin_ge_synthesizes_from_spaceship(const CustomGTAndSpaceship&, const CustomGTAndSpaceship&)); |
| 158 |
|
| 159 |
struct CustomGEAndSpaceship { |
| 160 |
int i; |
| 161 |
|
| 162 |
friend auto operator<=>(CustomGEAndSpaceship lhs, CustomGEAndSpaceship rhs) { |
| 163 |
return rhs.i <=> lhs.i; |
| 164 |
} |
| 165 |
|
| 166 |
friend auto operator>=(CustomGEAndSpaceship lhs, CustomGEAndSpaceship rhs) { |
| 167 |
return rhs.i < lhs.i; |
| 168 |
} |
| 169 |
}; |
| 170 |
|
| 171 |
static_assert(__builtin_lt_synthesizes_from_spaceship(const CustomGEAndSpaceship&, const CustomGEAndSpaceship&)); |
| 172 |
static_assert(__builtin_le_synthesizes_from_spaceship(const CustomGEAndSpaceship&, const CustomGEAndSpaceship&)); |
| 173 |
static_assert(__builtin_gt_synthesizes_from_spaceship(const CustomGEAndSpaceship&, const CustomGEAndSpaceship&)); |
| 174 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(const CustomGEAndSpaceship&, const CustomGEAndSpaceship&)); |
| 175 |
|
| 176 |
struct DefaultedCmpAndSpaceship { |
| 177 |
int i; |
| 178 |
|
| 179 |
friend auto operator<=>(DefaultedCmpAndSpaceship lhs, DefaultedCmpAndSpaceship rhs) { |
| 180 |
return rhs.i <=> lhs.i; |
| 181 |
} |
| 182 |
|
| 183 |
friend bool operator<(DefaultedCmpAndSpaceship lhs, DefaultedCmpAndSpaceship rhs) = default; |
| 184 |
friend bool operator<=(DefaultedCmpAndSpaceship lhs, DefaultedCmpAndSpaceship rhs) = default; |
| 185 |
friend bool operator>(DefaultedCmpAndSpaceship lhs, DefaultedCmpAndSpaceship rhs) = default; |
| 186 |
friend bool operator>=(DefaultedCmpAndSpaceship lhs, DefaultedCmpAndSpaceship rhs) = default; |
| 187 |
}; |
| 188 |
|
| 189 |
// TODO: This should probably return true |
| 190 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(const DefaultedCmpAndSpaceship&, const DefaultedCmpAndSpaceship&)); |
| 191 |
static_assert(!__builtin_le_synthesizes_from_spaceship(const DefaultedCmpAndSpaceship&, const DefaultedCmpAndSpaceship&)); |
| 192 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(const DefaultedCmpAndSpaceship&, const DefaultedCmpAndSpaceship&)); |
| 193 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(const DefaultedCmpAndSpaceship&, const DefaultedCmpAndSpaceship&)); |
| 194 |
|
| 195 |
struct DifferentTypes { |
| 196 |
int i; |
| 197 |
|
| 198 |
friend auto operator<=>(DifferentTypes lhs, int rhs) { |
| 199 |
return rhs <=> lhs.i; |
| 200 |
} |
| 201 |
}; |
| 202 |
|
| 203 |
static_assert(__builtin_lt_synthesizes_from_spaceship(const DifferentTypes&, const int&)); |
| 204 |
static_assert(__builtin_le_synthesizes_from_spaceship(const DifferentTypes&, const int&)); |
| 205 |
static_assert(__builtin_gt_synthesizes_from_spaceship(const DifferentTypes&, const int&)); |
| 206 |
static_assert(__builtin_ge_synthesizes_from_spaceship(const DifferentTypes&, const int&)); |
| 207 |
|
| 208 |
// TODO: Should this return true? It's technically not synthesized from spaceship, but it behaves exactly as-if it was |
| 209 |
static_assert(!__builtin_lt_synthesizes_from_spaceship(int, int)); |
| 210 |
static_assert(!__builtin_le_synthesizes_from_spaceship(int, int)); |
| 211 |
static_assert(!__builtin_gt_synthesizes_from_spaceship(int, int)); |
| 212 |
static_assert(!__builtin_ge_synthesizes_from_spaceship(int, int)); |