[llvm] 77f2ccb - [STLExtras] Add out-of-line definition of friend operator== for C++20 (#72348)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 01:49:54 PST 2024


Author: Utkarsh Saxena
Date: 2024-01-11T10:49:49+01:00
New Revision: 77f2ccbaac5e05e14827247ea8f6cc0f9d214390

URL: https://github.com/llvm/llvm-project/commit/77f2ccbaac5e05e14827247ea8f6cc0f9d214390
DIFF: https://github.com/llvm/llvm-project/commit/77f2ccbaac5e05e14827247ea8f6cc0f9d214390.diff

LOG: [STLExtras] Add out-of-line definition of friend operator== for C++20 (#72348)

The last attempt at https://github.com/llvm/llvm-project/pull/72220 was
reverted by
https://github.com/llvm/llvm-project/commit/94d6699bf5eeb5aa4c50d1d90f8bf69b79201ceb
because it breaks C++20 build in clang-17 and before.

This is a workaround of
https://github.com/llvm/llvm-project/issues/70210 and unblocks
https://github.com/llvm/llvm-project/pull/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 https://github.com/llvm/llvm-project/issues/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
https://github.com/llvm/llvm-project/pull/72213

Added: 
    

Modified: 
    llvm/docs/ReleaseNotes.rst
    llvm/include/llvm/ADT/STLExtras.h

Removed: 
    


################################################################################
diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 52610e7de18751..ebd3a4542361d9 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -73,6 +73,8 @@ Changes to the LLVM IR
 Changes to LLVM infrastructure
 ------------------------------
 
+* Minimum Clang version to build LLVM in C++20 configuration has been updated to clang-17.0.6.
+
 Changes to building LLVM
 ------------------------
 

diff  --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 18bc4d108b156b..a136eeb0ff1bd7 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1290,18 +1290,6 @@ class indexed_accessor_range_base {
     return (*this)[size() - 1];
   }
 
-  /// 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);
-  }
-
   /// Return the size of this range.
   size_t size() const { return count; }
 
@@ -1364,6 +1352,23 @@ class indexed_accessor_range_base {
   /// The size from the owning range.
   ptr
diff _t count;
 };
+/// Compare this range with another.
+/// FIXME: Make me a member function instead of friend when it works in C++20.
+template <typename OtherT, typename DerivedT, typename BaseT, typename T,
+          typename PointerT, typename ReferenceT>
+bool operator==(const indexed_accessor_range_base<DerivedT, BaseT, T, PointerT,
+                                                  ReferenceT> &lhs,
+                const OtherT &rhs) {
+  return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
+}
+
+template <typename OtherT, typename DerivedT, typename BaseT, typename T,
+          typename PointerT, typename ReferenceT>
+bool operator!=(const indexed_accessor_range_base<DerivedT, BaseT, T, PointerT,
+                                                  ReferenceT> &lhs,
+                const OtherT &rhs) {
+  return !(lhs == rhs);
+}
 } // end namespace detail
 
 /// This class provides an implementation of a range of


        


More information about the llvm-commits mailing list