[libcxx-commits] [libcxx] [libc++][chrono] Remove non-standard relational operators for `std::chrono::weekday` (PR #98730)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 14 01:00:28 PDT 2024


https://github.com/frederick-vs-ja updated https://github.com/llvm/llvm-project/pull/98730

>From f5ebe5d039618519a169f379b3be042003da6bd9 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sat, 13 Jul 2024 17:20:43 +0800
Subject: [PATCH 1/3] [libc++] Remove relational operators for
 `std::chrono::weekday`

---
 libcxx/docs/ReleaseNotes/19.rst                             | 6 ++++++
 libcxx/include/__chrono/weekday.h                           | 3 +++
 .../time.cal.weekday.nonmembers/comparisons.pass.cpp        | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index a4cf411d2a6c1..623aab42a8f16 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -134,6 +134,12 @@ Deprecations and Removals
   `std-allocator-const <https://clang.llvm.org/extra/clang-tidy/checks/portability/std-allocator-const.html>`
   enabled.
 
+- libc++ no longer supports relational comparison for ``std::chrono::weekday``. The relational comparison operators were
+  provided as an undocumented extension. If you were using relational comparison on ``std::chrono::weekday``, compare
+  the results of ``c_encoding()`` or ``iso_encoding()`` instead. The
+  ``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro can be defined to temporarily re-enable this extension
+  as folks transition their code. This macro will be honored for one released and ignored starting in LLVM 20.
+
 
 Upcoming Deprecations and Removals
 ----------------------------------
diff --git a/libcxx/include/__chrono/weekday.h b/libcxx/include/__chrono/weekday.h
index 5a7dedc6e3a16..86c780cc71825 100644
--- a/libcxx/include/__chrono/weekday.h
+++ b/libcxx/include/__chrono/weekday.h
@@ -79,6 +79,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday& __lhs, con
   return __lhs.c_encoding() == __rhs.c_encoding();
 }
 
+// TODO(LLVM 20): Remove the escape hatch
+#  ifdef _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS
 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<(const weekday& __lhs, const weekday& __rhs) noexcept {
   return __lhs.c_encoding() < __rhs.c_encoding();
 }
@@ -94,6 +96,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<=(const weekday& __lhs, con
 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept {
   return !(__lhs < __rhs);
 }
+#  endif // _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept {
   auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
diff --git a/libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp b/libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp
index 33d8cd9f776d2..0101d205b5555 100644
--- a/libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp
+++ b/libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp
@@ -17,10 +17,13 @@
 #include <chrono>
 #include <type_traits>
 #include <cassert>
+#include <concepts>
 
 #include "test_macros.h"
 #include "test_comparisons.h"
 
+static_assert(!std::totally_ordered<std::chrono::weekday>);
+
 int main(int, char**)
 {
     using weekday = std::chrono::weekday;

>From cd4ec4c3db18fdbb66eb5bed7510fea61a5e3cc4 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sat, 13 Jul 2024 22:56:25 +0800
Subject: [PATCH 2/3] Address @mordante's review comments

Co-authored-by: Mark de Wever <zar-rpg at xs4all.nl>
---
 libcxx/docs/ReleaseNotes/19.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index 623aab42a8f16..fff61f9613622 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -137,8 +137,8 @@ Deprecations and Removals
 - libc++ no longer supports relational comparison for ``std::chrono::weekday``. The relational comparison operators were
   provided as an undocumented extension. If you were using relational comparison on ``std::chrono::weekday``, compare
   the results of ``c_encoding()`` or ``iso_encoding()`` instead. The
-  ``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro can be defined to temporarily re-enable this extension
-  as folks transition their code. This macro will be honored for one released and ignored starting in LLVM 20.
+  ``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro can be defined to temporarily re-enable this extension.
+  This macro will be honored for one released and ignored starting in LLVM 20.
 
 
 Upcoming Deprecations and Removals

>From 2fb3ac92898f32b2b06d1718ae73ce9209c1dd05 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sun, 14 Jul 2024 16:00:20 +0800
Subject: [PATCH 3/3] Address @h-vetinari's review comments

Fixing typo.

Co-authored-by: h-vetinari <h.vetinari at gmx.com>
---
 libcxx/docs/ReleaseNotes/19.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index fff61f9613622..1a3644f199193 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -138,7 +138,7 @@ Deprecations and Removals
   provided as an undocumented extension. If you were using relational comparison on ``std::chrono::weekday``, compare
   the results of ``c_encoding()`` or ``iso_encoding()`` instead. The
   ``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro can be defined to temporarily re-enable this extension.
-  This macro will be honored for one released and ignored starting in LLVM 20.
+  This macro will be honored for one release and ignored starting in LLVM 20.
 
 
 Upcoming Deprecations and Removals



More information about the libcxx-commits mailing list