Skip to content

Commit 849b964

Browse files
mordanteyuxuanchen1997
authored andcommitted
[libc++] Deprecates rel_ops. (#91642)
Summary: These operators were deprecated in P0768R1 Library Support for the Spaceship (Comparison) Operator This was discovered while investigating the paper's implementation status. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250952
1 parent 82296bd commit 849b964

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

libcxx/docs/ReleaseNotes/19.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Deprecations and Removals
141141
of randomness, and others. Users that were checking whether including a header would fail (e.g. via a script
142142
or CMake's ``try_compile`` will experience a change in behavior).
143143

144+
- The operators in the ``rel_ops`` namespace have been deprecated. The deprecation is part of the paper
145+
P0768R1 "Library Support for the Spaceship (Comparison) Operator".
144146

145147
Upcoming Deprecations and Removals
146148
----------------------------------

libcxx/include/__utility/rel_ops.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020
namespace rel_ops {
2121

2222
template <class _Tp>
23-
inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const _Tp& __x, const _Tp& __y) {
23+
inline _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator!=(const _Tp& __x, const _Tp& __y) {
2424
return !(__x == __y);
2525
}
2626

2727
template <class _Tp>
28-
inline _LIBCPP_HIDE_FROM_ABI bool operator>(const _Tp& __x, const _Tp& __y) {
28+
inline _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator>(const _Tp& __x, const _Tp& __y) {
2929
return __y < __x;
3030
}
3131

3232
template <class _Tp>
33-
inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const _Tp& __x, const _Tp& __y) {
33+
inline _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator<=(const _Tp& __x, const _Tp& __y) {
3434
return !(__y < __x);
3535
}
3636

3737
template <class _Tp>
38-
inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const _Tp& __x, const _Tp& __y) {
38+
inline _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator>=(const _Tp& __x, const _Tp& __y) {
3939
return !(__x < __y);
4040
}
4141

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <utility>
10+
11+
// UNSUPPORTED: c++03, c++11, c++14, c++17
12+
13+
#include <utility>
14+
#include <cassert>
15+
16+
struct A {
17+
int data_ = 0;
18+
};
19+
20+
inline bool operator==(const A& x, const A& y) { return x.data_ == y.data_; }
21+
22+
inline bool operator<(const A& x, const A& y) { return x.data_ < y.data_; }
23+
24+
void test() {
25+
using namespace std::rel_ops;
26+
A a1{1};
27+
A a2{2};
28+
(void)(a1 == a1);
29+
(void)(a1 != a2); // note not deprecated message, due to compiler generated operator.
30+
std::rel_ops::operator!=(a1, a2); // expected-warning {{is deprecated}}
31+
(void)(a1 < a2);
32+
(void)(a1 > a2); // expected-warning 2 {{is deprecated}}
33+
(void)(a1 <= a2); // expected-warning 2 {{is deprecated}}
34+
(void)(a1 >= a2); // expected-warning 2 {{is deprecated}}
35+
}

libcxx/test/std/containers/iterator.rel_ops.compile.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
// XFAIL: availability-filesystem-missing
1010

11+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
12+
1113
// Make sure the various containers' iterators are not broken by the use of `std::rel_ops`.
1214

1315
#include <utility> // for std::rel_ops

libcxx/test/std/utilities/utility/operators/rel_ops.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
// test rel_ops
1010

11+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
12+
1113
#include <utility>
1214
#include <cassert>
1315

0 commit comments

Comments
 (0)