Skip to content

Commit 77f2ccb

Browse files
authored
[STLExtras] Add out-of-line definition of friend operator== for C++20 (#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
1 parent 75d820d commit 77f2ccb

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Changes to the LLVM IR
7373
Changes to LLVM infrastructure
7474
------------------------------
7575

76+
* Minimum Clang version to build LLVM in C++20 configuration has been updated to clang-17.0.6.
77+
7678
Changes to building LLVM
7779
------------------------
7880

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,18 +1290,6 @@ class indexed_accessor_range_base {
12901290
return (*this)[size() - 1];
12911291
}
12921292

1293-
/// Compare this range with another.
1294-
template <typename OtherT>
1295-
friend bool operator==(const indexed_accessor_range_base &lhs,
1296-
const OtherT &rhs) {
1297-
return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1298-
}
1299-
template <typename OtherT>
1300-
friend bool operator!=(const indexed_accessor_range_base &lhs,
1301-
const OtherT &rhs) {
1302-
return !(lhs == rhs);
1303-
}
1304-
13051293
/// Return the size of this range.
13061294
size_t size() const { return count; }
13071295

@@ -1364,6 +1352,23 @@ class indexed_accessor_range_base {
13641352
/// The size from the owning range.
13651353
ptrdiff_t count;
13661354
};
1355+
/// Compare this range with another.
1356+
/// FIXME: Make me a member function instead of friend when it works in C++20.
1357+
template <typename OtherT, typename DerivedT, typename BaseT, typename T,
1358+
typename PointerT, typename ReferenceT>
1359+
bool operator==(const indexed_accessor_range_base<DerivedT, BaseT, T, PointerT,
1360+
ReferenceT> &lhs,
1361+
const OtherT &rhs) {
1362+
return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1363+
}
1364+
1365+
template <typename OtherT, typename DerivedT, typename BaseT, typename T,
1366+
typename PointerT, typename ReferenceT>
1367+
bool operator!=(const indexed_accessor_range_base<DerivedT, BaseT, T, PointerT,
1368+
ReferenceT> &lhs,
1369+
const OtherT &rhs) {
1370+
return !(lhs == rhs);
1371+
}
13671372
} // end namespace detail
13681373

13691374
/// This class provides an implementation of a range of

0 commit comments

Comments
 (0)