Skip to content

Commit 7fb19cb

Browse files
[ADT] Require base equality in indexed_accessor_iterator::operator==() (#107856)
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).
1 parent 524a028 commit 7fb19cb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/include/llvm/ADT/STLExtras.h

+2-1
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)