[libcxx-commits] [libcxx] [libc++] Deprecates rel_ops. (PR #91642)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jul 6 03:21:16 PDT 2024


https://github.com/mordante updated https://github.com/llvm/llvm-project/pull/91642

>From 02dc129a6ccc7f71de4effc10e72b38aa13bc49e Mon Sep 17 00:00:00 2001
From: Mark de Wever <koraq at xs4all.nl>
Date: Thu, 9 May 2024 20:32:09 +0200
Subject: [PATCH] [libc++] Deprecates rel_ops.

These operators were deprecated in
  P0768R1 Library Support for the Spaceship (Comparison) Operator

This was discovered while investigating the paper's implementation
status.
---
 libcxx/docs/ReleaseNotes/19.rst               |  2 ++
 libcxx/include/__utility/rel_ops.h            |  8 ++---
 .../rel_ops.depr_in_cxx20.verify.cpp          | 35 +++++++++++++++++++
 .../iterator.rel_ops.compile.pass.cpp         |  2 ++
 .../utility/operators/rel_ops.pass.cpp        |  2 ++
 5 files changed, 45 insertions(+), 4 deletions(-)
 create mode 100644 libcxx/test/libcxx/depr/depr.rel_ops/rel_ops.depr_in_cxx20.verify.cpp

diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index d30021b7eb234..7dd8d5f4d1cee 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -130,6 +130,8 @@ Deprecations and Removals
   `std-allocator-const <https://clang.llvm.org/extra/clang-tidy/checks/portability/std-allocator-const.html>`
   enabled.
 
+- The operators in the ``rel_ops`` namespace have been deprecated. The deprecation is part of the paper
+  P0768R1 "Library Support for the Spaceship (Comparison) Operator".
 
 Upcoming Deprecations and Removals
 ----------------------------------
diff --git a/libcxx/include/__utility/rel_ops.h b/libcxx/include/__utility/rel_ops.h
index ee8657196d98c..a8caf5bdeaf27 100644
--- a/libcxx/include/__utility/rel_ops.h
+++ b/libcxx/include/__utility/rel_ops.h
@@ -20,22 +20,22 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace rel_ops {
 
 template <class _Tp>
-inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const _Tp& __x, const _Tp& __y) {
+inline _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator!=(const _Tp& __x, const _Tp& __y) {
   return !(__x == __y);
 }
 
 template <class _Tp>
-inline _LIBCPP_HIDE_FROM_ABI bool operator>(const _Tp& __x, const _Tp& __y) {
+inline _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator>(const _Tp& __x, const _Tp& __y) {
   return __y < __x;
 }
 
 template <class _Tp>
-inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const _Tp& __x, const _Tp& __y) {
+inline _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator<=(const _Tp& __x, const _Tp& __y) {
   return !(__y < __x);
 }
 
 template <class _Tp>
-inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const _Tp& __x, const _Tp& __y) {
+inline _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator>=(const _Tp& __x, const _Tp& __y) {
   return !(__x < __y);
 }
 
diff --git a/libcxx/test/libcxx/depr/depr.rel_ops/rel_ops.depr_in_cxx20.verify.cpp b/libcxx/test/libcxx/depr/depr.rel_ops/rel_ops.depr_in_cxx20.verify.cpp
new file mode 100644
index 0000000000000..2f7f46ac1ad6d
--- /dev/null
+++ b/libcxx/test/libcxx/depr/depr.rel_ops/rel_ops.depr_in_cxx20.verify.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <utility>
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+#include <utility>
+#include <cassert>
+
+struct A {
+  int data_ = 0;
+};
+
+inline bool operator==(const A& x, const A& y) { return x.data_ == y.data_; }
+
+inline bool operator<(const A& x, const A& y) { return x.data_ < y.data_; }
+
+void test() {
+  using namespace std::rel_ops;
+  A a1(1);
+  A a2(2);
+  (void)(a1 == a1);
+  (void)(a1 != a2);                 // note not deprecated message, due to compiler generated operator.
+  std::rel_ops::operator!=(a1, a2); // expected-warning {{is deprecated}}
+  (void)(a1 < a2);
+  (void)(a1 > a2);  // expected-warning 2 {{is deprecated}}
+  (void)(a1 <= a2); // expected-warning 2 {{is deprecated}}
+  (void)(a1 >= a2); // expected-warning 2 {{is deprecated}}
+}
diff --git a/libcxx/test/std/containers/iterator.rel_ops.compile.pass.cpp b/libcxx/test/std/containers/iterator.rel_ops.compile.pass.cpp
index aaaa887f72074..9db2449f2f166 100644
--- a/libcxx/test/std/containers/iterator.rel_ops.compile.pass.cpp
+++ b/libcxx/test/std/containers/iterator.rel_ops.compile.pass.cpp
@@ -8,6 +8,8 @@
 
 // XFAIL: availability-filesystem-missing
 
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
+
 // Make sure the various containers' iterators are not broken by the use of `std::rel_ops`.
 
 #include <utility> // for std::rel_ops
diff --git a/libcxx/test/std/utilities/utility/operators/rel_ops.pass.cpp b/libcxx/test/std/utilities/utility/operators/rel_ops.pass.cpp
index 52ed642274114..db0c7a61bddd6 100644
--- a/libcxx/test/std/utilities/utility/operators/rel_ops.pass.cpp
+++ b/libcxx/test/std/utilities/utility/operators/rel_ops.pass.cpp
@@ -8,6 +8,8 @@
 
 // test rel_ops
 
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
+
 #include <utility>
 #include <cassert>
 



More information about the libcxx-commits mailing list