Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
[STLExtras] Add out-of-line definition of friend operator== for C++20…
Browse files Browse the repository at this point in the history
… (#72348)

The last attempt at llvm/llvm-project#72220 was
reverted by
llvm/llvm-project@94d6699
because it breaks C++20 build in clang-17 and before.

This is a workaround of
llvm/llvm-project#70210 and unblocks
llvm/llvm-project#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/llvm-project#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/llvm-project#72213
  • Loading branch information
usx95 authored Jan 11, 2024
1 parent 75d820d commit 77f2ccb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------

Expand Down
29 changes: 17 additions & 12 deletions llvm/include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -1364,6 +1352,23 @@ class indexed_accessor_range_base {
/// The size from the owning range.
ptrdiff_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
Expand Down

0 comments on commit 77f2ccb

Please sign in to comment.