-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[STLExtras] Remove incorrect hack to make indexed_accessor_range operator== compatible with C++20 #72220
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-llvm-adt Author: Utkarsh Saxena (usx95) ChangesThis partially reverts c312f02 The motivation behind this is unclear and the change predates the clang implementation of https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2468r2.html so I am not sure if it was ever intended to work. Rewritten template operators were broken since the beginning. Moreover, moving away from Full diff: https://github.com/llvm/llvm-project/pull/72220.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 18bc4d108b156bf..e42b0e8d1b27b71 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1291,15 +1291,11 @@ class indexed_accessor_range_base {
}
/// Compare this range with another.
- template <typename OtherT>
- friend bool operator==(const indexed_accessor_range_base &lhs,
- const OtherT &rhs) {
- return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
- }
- template <typename OtherT>
- friend bool operator!=(const indexed_accessor_range_base &lhs,
- const OtherT &rhs) {
- return !(lhs == rhs);
+ template <typename OtherT> bool operator==(const OtherT &rhs) const {
+ return std::equal(begin(), end(), rhs.begin(), rhs.end());
+ }
+ template <typename OtherT> bool operator!=(const OtherT &rhs) const {
+ return !(*this == rhs);
}
/// Return the size of this range.
|
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.
Fine with me, but I suppose this will break older clangs just like e558be5 did. Is everyone building clang in C++20 mode on a newer version now?
I am testing if our internal builds and the buildbot will break with this change. I have previously assumed they would break, but there were other patches flying around at the same time so maybe I had missed something. It'd be nice if we could land this change and it'd work with some released version of Clang and Clang at head. I'll post the results of my investigation when I'm done. |
Both internal and buildbot builds should be fine after this change. LGTM! |
…ator== compatible with C++20 (llvm#72220) This partially reverts c312f02 The motivation behind this is unclear and the change predates the clang [implementation](llvm@38b9d31) of [p2468r2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2468r2.html) so I am not sure if it was ever intended to work. Rewritten template operators were broken since the beginning. Moreover, moving away from `friend` would be beneficial as these would only accepted once clang revises its implementation for fixing llvm#70210. It also helps in making sure that older compilers still compile LLVM (in C++20).
…nge operator== compatible with C++20" (llvm#72265) Reverts llvm#72220 This breaks C++20 build bot. Need to see if upgrading to clang-17 in the build bot would solve the issue.
…#72348) The last attempt at #72220 was reverted by 94d6699 because it breaks C++20 build in clang-17 and before. This is a workaround of #70210 and unblocks #72213 which rectifies rewriting template operator and thus introduces new breakages. Moving the function definition out of the class makes clang find a matching `operator!=` for the `operator==`. This makes clang not rewrite the `operator==` with reversed args. Hence, the ambiguity is resolved. The final plan, when #70210 is fixed, is to move these back to inline definition or even convert to a member template operator. This should not be urgent and could even wait for a major clang release including #72213
…llvm#72348) The last attempt at llvm#72220 was reverted by llvm@94d6699 because it breaks C++20 build in clang-17 and before. This is a workaround of llvm#70210 and unblocks llvm#72213 which rectifies rewriting template operator and thus introduces new breakages. Moving the function definition out of the class makes clang find a matching `operator!=` for the `operator==`. This makes clang not rewrite the `operator==` with reversed args. Hence, the ambiguity is resolved. The final plan, when llvm#70210 is fixed, is to move these back to inline definition or even convert to a member template operator. This should not be urgent and could even wait for a major clang release including llvm#72213
This partially reverts c312f02
The motivation behind this is unclear and the change predates the clang implementation of p2468r2 so I am not sure if it was ever intended to work. Rewritten template operators were broken since the beginning.
Moreover, moving away from
friend
would be beneficial as these would only accepted once clang revises its implementation for fixing #70210. It also helps in making sure that older compilers still compile LLVM (in C++20).