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

Conversation

frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Jul 13, 2024

These operators are absent in [time.syn], and a note in [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.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner July 13, 2024 09:27
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 13, 2024

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

These operators are absent in [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.


Full diff: https://github.com/llvm/llvm-project/pull/98730.diff

3 Files Affected:

  • (modified) libcxx/docs/ReleaseNotes/19.rst (+6)
  • (modified) libcxx/include/__chrono/weekday.h (+3)
  • (modified) libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp (+3)
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;

Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

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

Nice catch! LGTM modulo a minor comment.


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

Fixing typo.

Co-authored-by: h-vetinari <[email protected]>
Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

Good find, thanks for the patch!

@mordante mordante self-assigned this Jul 16, 2024
@ldionne ldionne merged commit 684a615 into llvm:main Jul 18, 2024
10 of 12 checks passed
@frederick-vs-ja frederick-vs-ja deleted the no-ordered-weekday branch July 18, 2024 14:36
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…hrono::weekday` (#98730)

Summary:
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.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250911
philnik777 pushed a commit that referenced this pull request Jan 10, 2025
BaiXilin pushed a commit to BaiXilin/llvm-fix-vnni-instr-types that referenced this pull request Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants