[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
Sat Jul 13 02:27:27 PDT 2024
https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/98730
These operators are absent in [[time.syn]](https://eel.is/c++draft/time.syn), and a note [[time.cal.wd.overview]/1](https://eel.is/c++draft/time.cal.wd.overview#1) indicates that the absence is intended.
This patch removes the undocumented extension, while providing a migration path for vendors by providing the `_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS` macro. This macro will be honored for the LLVM 19 release and will be removed after that, at which point allocator will be removed unconditionally.
>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] [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;
More information about the libcxx-commits
mailing list