Skip to content

[libc++][chrono] Remove non-standard relational operators for std::chrono::weekday #98730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libcxx/docs/ReleaseNotes/19.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ Deprecations and Removals
of randomness, and others. Users that were checking whether including a header would fail (e.g. via a script
or CMake's ``try_compile`` will experience a change in behavior).

- 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.
This macro will be honored for one release and ignored starting in LLVM 20.

- 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".

Expand All @@ -157,6 +163,10 @@ LLVM 20

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

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

LLVM 21
~~~~~~~
TODO
Expand Down
4 changes: 4 additions & 0 deletions libcxx/docs/ReleaseNotes/20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Deprecations and Removals

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

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


Upcoming Deprecations and Removals
----------------------------------
Expand Down
3 changes: 3 additions & 0 deletions libcxx/include/__chrono/weekday.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting the relational operations are never tested.


int main(int, char**)
{
using weekday = std::chrono::weekday;
Expand Down
Loading