Skip to content

Commit 684a615

Browse files
[libc++][chrono] Remove non-standard relational operators for std::chrono::weekday (#98730)
These operators are absent in https://eel.is/c++draft/time.syn and a note in 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.
1 parent a778909 commit 684a615

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

libcxx/docs/ReleaseNotes/19.rst

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

146+
- libc++ no longer supports relational comparison for ``std::chrono::weekday``. The relational comparison operators were
147+
provided as an undocumented extension. If you were using relational comparison on ``std::chrono::weekday``, compare
148+
the results of ``c_encoding()`` or ``iso_encoding()`` instead. The
149+
``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro can be defined to temporarily re-enable this extension.
150+
This macro will be honored for one release and ignored starting in LLVM 20.
151+
146152
- The operators in the ``rel_ops`` namespace have been deprecated. The deprecation is part of the paper
147153
P0768R1 "Library Support for the Spaceship (Comparison) Operator".
148154

@@ -157,6 +163,10 @@ LLVM 20
157163

158164
- The C++20 synchronization library will be removed entirely in language modes prior to C++20 in LLVM 20.
159165

166+
- The relational operators for ``std::chrono::weekday`` will be removed entirely, and the
167+
``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro that was used to re-enable this extension will be
168+
ignored in LLVM 20.
169+
160170
LLVM 21
161171
~~~~~~~
162172
TODO

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Deprecations and Removals
5555

5656
- TODO: The C++20 synchronization library will be removed entirely in language modes prior to C++20 in LLVM 20.
5757

58+
- TODO: The relational operators for ``std::chrono::weekday`` will be removed entirely, and the
59+
``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro that was used to re-enable this extension will be
60+
ignored in LLVM 20.
61+
5862

5963
Upcoming Deprecations and Removals
6064
----------------------------------

libcxx/include/__chrono/weekday.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday& __lhs, con
7979
return __lhs.c_encoding() == __rhs.c_encoding();
8080
}
8181

82+
// TODO(LLVM 20): Remove the escape hatch
83+
# ifdef _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS
8284
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<(const weekday& __lhs, const weekday& __rhs) noexcept {
8385
return __lhs.c_encoding() < __rhs.c_encoding();
8486
}
@@ -94,6 +96,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<=(const weekday& __lhs, con
9496
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept {
9597
return !(__lhs < __rhs);
9698
}
99+
# endif // _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS
97100

98101
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept {
99102
auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();

libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
#include <chrono>
1818
#include <type_traits>
1919
#include <cassert>
20+
#include <concepts>
2021

2122
#include "test_macros.h"
2223
#include "test_comparisons.h"
2324

25+
static_assert(!std::totally_ordered<std::chrono::weekday>);
26+
2427
int main(int, char**)
2528
{
2629
using weekday = std::chrono::weekday;

0 commit comments

Comments
 (0)