Skip to content

[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

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

usx95
Copy link
Contributor

@usx95 usx95 commented Nov 14, 2023

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

@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2023

@llvm/pr-subscribers-llvm-adt

Author: Utkarsh Saxena (usx95)

Changes

This 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 friend would be beneficial as these would only accepted once clang revises its implementation to fix #70210. It also helps in making sure that older compilers still compile LLVM.


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/STLExtras.h (+5-9)
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.

@usx95 usx95 requested a review from d0k November 14, 2023 09:48
Copy link
Member

@d0k d0k left a 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?

@ilya-biryukov
Copy link
Contributor

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.

@ilya-biryukov
Copy link
Contributor

Both internal and buildbot builds should be fine after this change.
And they should keep working after #72213 lands because it does some extra checks to report those cases as warnings rather than errors (hence, won't break the builds either).

LGTM!

@usx95 usx95 merged commit 2be3fca into llvm:main Nov 14, 2023
usx95 added a commit that referenced this pull request Nov 14, 2023
…nge operator== compatible with C++20 (#72220)"

This reverts commit 2be3fca.
usx95 added a commit that referenced this pull request Nov 14, 2023
…nge operator== compatible with C++20" (#72265)

Reverts #72220

This breaks C++20 build bot. Need to see if upgrading to clang-17 in the
build bot would solve the issue.
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
…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).
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
…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.
usx95 added a commit that referenced this pull request Jan 11, 2024
…#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
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants