From 6de7c57fd17a79a477d8384a0d6b929b5190e6cc Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Tue, 10 Sep 2024 20:29:57 +0300 Subject: [PATCH] [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). --- llvm/include/llvm/ADT/STLExtras.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index a136eeb0ff1b..73cfa90baac0 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -1203,7 +1203,8 @@ class indexed_accessor_iterator return index - rhs.index; } bool operator==(const indexed_accessor_iterator &rhs) const { - return base == rhs.base && index == rhs.index; + assert(base == rhs.base && "incompatible iterators"); + return index == rhs.index; } bool operator<(const indexed_accessor_iterator &rhs) const { assert(base == rhs.base && "incompatible iterators");