Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.

Commit 3d353a3

Browse files
nikita-kudandrey-golubev
authored andcommitted
[ADT] Require base equality in indexed_accessor_iterator::operator==() (#107856) (#64)
Similarly to operator<(), equality-comparing iterators from different ranges must really be forbidden. The preconditions for being able to do `it1 < it2` and `it1 != it2` (or `it1 == it2` for the matter) ought to be the same. Thus, there's little sense in keeping explicit base object comparison in operator==() whilst having this is a precondition in operator<() and operator-() (e.g. used for std::distance() and such). Co-authored-by: Andrei Golubev <[email protected]>
1 parent 4bcc62f commit 3d353a3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,8 @@ class indexed_accessor_iterator
11941194
return index - rhs.index;
11951195
}
11961196
bool operator==(const indexed_accessor_iterator &rhs) const {
1197-
return base == rhs.base && index == rhs.index;
1197+
assert(base == rhs.base && "incompatible iterators");
1198+
return index == rhs.index;
11981199
}
11991200
bool operator<(const indexed_accessor_iterator &rhs) const {
12001201
assert(base == rhs.base && "incompatible iterators");

0 commit comments

Comments
 (0)