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

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 18 06:58:40 PDT 2024


Author: A. Jiang
Date: 2024-07-18T09:58:35-04:00
New Revision: 684a61506a3ddc943b8baef1d14c96bbf82e6c04

URL: https://github.com/llvm/llvm-project/commit/684a61506a3ddc943b8baef1d14c96bbf82e6c04
DIFF: https://github.com/llvm/llvm-project/commit/684a61506a3ddc943b8baef1d14c96bbf82e6c04.diff

LOG: [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.

Added: 
    

Modified: 
    libcxx/docs/ReleaseNotes/19.rst
    libcxx/docs/ReleaseNotes/20.rst
    libcxx/include/__chrono/weekday.h
    libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index a28dae52e8579..36cb23dfde6c9 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -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".
 
@@ -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

diff  --git a/libcxx/docs/ReleaseNotes/20.rst b/libcxx/docs/ReleaseNotes/20.rst
index 79b9788f92eda..fb677b1667ddc 100644
--- a/libcxx/docs/ReleaseNotes/20.rst
+++ b/libcxx/docs/ReleaseNotes/20.rst
@@ -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
 ----------------------------------

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