Skip to content

Commit 20506fb

Browse files
committed
[libcxx] removes operator!= and globally guards against no spaceship operator
* `operator!=` isn't in the spec * `<compare>` is designed to work with `operator<=>` so it doesn't really make sense to have `operator<=>`-less friendly sections. Depends on D100283. Differential Revision: https://reviews.llvm.org/D100342
1 parent 888307e commit 20506fb

File tree

5 files changed

+6
-62
lines changed

5 files changed

+6
-62
lines changed

libcxx/include/compare

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ namespace std {
129129

130130
_LIBCPP_BEGIN_NAMESPACE_STD
131131

132-
#if _LIBCPP_STD_VER > 17
133-
132+
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
134133
// exposition only
135134
enum class _LIBCPP_ENUM_VIS _EqResult : unsigned char {
136135
__zero = 0,
@@ -184,24 +183,19 @@ public:
184183

185184
// comparisons
186185
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
187-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
188186
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept;
189187
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
190188
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept;
191189
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
192-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
193-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
194190
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept;
195191
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
196192
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept;
197193
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
198194

199-
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
200195
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
201196

202197
_LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
203198
_LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
204-
#endif
205199

206200
private:
207201
_ValueT __value_;
@@ -233,10 +227,6 @@ constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
233227
return __v.__is_ordered() && __v.__value_ >= 0;
234228
}
235229

236-
_LIBCPP_INLINE_VISIBILITY
237-
constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
238-
return __v.__is_ordered() && 0 == __v.__value_;
239-
}
240230
_LIBCPP_INLINE_VISIBILITY
241231
constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
242232
return __v.__is_ordered() && 0 < __v.__value_;
@@ -254,16 +244,6 @@ constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
254244
return __v.__is_ordered() && 0 >= __v.__value_;
255245
}
256246

257-
_LIBCPP_INLINE_VISIBILITY
258-
constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
259-
return !__v.__is_ordered() || __v.__value_ != 0;
260-
}
261-
_LIBCPP_INLINE_VISIBILITY
262-
constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
263-
return !__v.__is_ordered() || __v.__value_ != 0;
264-
}
265-
266-
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
267247
_LIBCPP_INLINE_VISIBILITY
268248
constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
269249
return __v;
@@ -272,7 +252,6 @@ _LIBCPP_INLINE_VISIBILITY
272252
constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
273253
return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
274254
}
275-
#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
276255

277256
class weak_ordering {
278257
using _ValueT = signed char;
@@ -295,24 +274,19 @@ public:
295274

296275
// comparisons
297276
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
298-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
299277
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept;
300278
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
301279
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept;
302280
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
303-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
304-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
305281
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept;
306282
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
307283
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept;
308284
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
309285

310-
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
311286
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
312287

313288
_LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
314289
_LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
315-
#endif
316290

317291
private:
318292
_ValueT __value_;
@@ -327,10 +301,6 @@ constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
327301
return __v.__value_ == 0;
328302
}
329303
_LIBCPP_INLINE_VISIBILITY
330-
constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
331-
return __v.__value_ != 0;
332-
}
333-
_LIBCPP_INLINE_VISIBILITY
334304
constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
335305
return __v.__value_ < 0;
336306
}
@@ -347,14 +317,6 @@ constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
347317
return __v.__value_ >= 0;
348318
}
349319
_LIBCPP_INLINE_VISIBILITY
350-
constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
351-
return 0 == __v.__value_;
352-
}
353-
_LIBCPP_INLINE_VISIBILITY
354-
constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
355-
return 0 != __v.__value_;
356-
}
357-
_LIBCPP_INLINE_VISIBILITY
358320
constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
359321
return 0 < __v.__value_;
360322
}
@@ -371,7 +333,6 @@ constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
371333
return 0 >= __v.__value_;
372334
}
373335

374-
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
375336
_LIBCPP_INLINE_VISIBILITY
376337
constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
377338
return __v;
@@ -380,8 +341,6 @@ _LIBCPP_INLINE_VISIBILITY
380341
constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
381342
return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
382343
}
383-
#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
384-
385344
class strong_ordering {
386345
using _ValueT = signed char;
387346

@@ -411,24 +370,19 @@ public:
411370

412371
// comparisons
413372
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
414-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
415373
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept;
416374
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
417375
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept;
418376
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
419-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
420-
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
421377
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept;
422378
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
423379
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept;
424380
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
425381

426-
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
427382
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
428383

429384
_LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
430385
_LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
431-
#endif
432386

433387
private:
434388
_ValueT __value_;
@@ -444,10 +398,6 @@ constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
444398
return __v.__value_ == 0;
445399
}
446400
_LIBCPP_INLINE_VISIBILITY
447-
constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
448-
return __v.__value_ != 0;
449-
}
450-
_LIBCPP_INLINE_VISIBILITY
451401
constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
452402
return __v.__value_ < 0;
453403
}
@@ -464,14 +414,6 @@ constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
464414
return __v.__value_ >= 0;
465415
}
466416
_LIBCPP_INLINE_VISIBILITY
467-
constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
468-
return 0 == __v.__value_;
469-
}
470-
_LIBCPP_INLINE_VISIBILITY
471-
constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
472-
return 0 != __v.__value_;
473-
}
474-
_LIBCPP_INLINE_VISIBILITY
475417
constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
476418
return 0 < __v.__value_;
477419
}
@@ -488,7 +430,6 @@ constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
488430
return 0 >= __v.__value_;
489431
}
490432

491-
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
492433
_LIBCPP_INLINE_VISIBILITY
493434
constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
494435
return __v;
@@ -497,7 +438,6 @@ _LIBCPP_INLINE_VISIBILITY
497438
constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
498439
return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
499440
}
500-
#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
501441

502442
// named comparison functions
503443
_LIBCPP_INLINE_VISIBILITY
@@ -582,7 +522,7 @@ template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, con
582522
template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
583523
template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
584524

585-
#endif // _LIBCPP_STD_VER > 17
525+
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR)
586526

587527
_LIBCPP_END_NAMESPACE_STD
588528

libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//===----------------------------------------------------------------------===//
99

1010
// UNSUPPORTED: c++03, c++11, c++14, c++17
11+
// UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11, apple-clang-12.0.0
1112

1213
// <compare>
1314

libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
// UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11, apple-clang-12.0.0
1011

1112
// <compare>
1213

libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
// UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11, apple-clang-12.0.0
1011

1112
// <compare>
1213

libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
// UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11, apple-clang-12.0.0
1011

1112
// <compare>
1213

0 commit comments

Comments
 (0)