-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-libcxx Author: A. Jiang (frederick-vs-ja) ChangesThese 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 Full diff: https://github.com/llvm/llvm-project/pull/98730.diff 3 Files Affected:
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;
|
There was a problem hiding this 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>); |
There was a problem hiding this comment.
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.
Co-authored-by: Mark de Wever <[email protected]>
Fixing typo. Co-authored-by: h-vetinari <[email protected]>
There was a problem hiding this 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!
Updating LLVM 20 entries in 19.rst and 20.rst.
…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
…o::weekday` (llvm#122428) Follows-up llvm#98730.
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.