C++s iterator concept requires operator* to return the same type as is specified by the iterators reference type. This functionality is especially important for older generic code that did not yet make use of auto.
An example from within LLVM is iterator_adaptor_base which uses the reference type of the iterator it is wrapping as its return type for operator* (this class is used as base for a lot of other functionality like filter iterators and so on).
Using any of the graph traversal iterators listed above with it would previously fail to compile due to reference being non-const while operator* returned a const reference.
This patch fixes that by correctly specifying reference and using it as the return type of operator* explicitly to prevent further issues in the future.
Could we add const conditionally, either with some type traits or define reference in terms of decltype(*declval<pointer>())?
Do you know if it there's any existing use of non-const references with these iterators?