https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113202

--- Comment #9 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Carsten Schmidt from comment #6)
> > Why do you think this is a bug?
> 
> 1. Considering the "possible implementation" of cppreference.com, pointer
>    arithmetic, e.g. ptr-ptr, should not be an issue when searching for the
>    sentinel.

Quoting from https://en.cppreference.com/w/cpp/iterator:

<quote>
An iterator j is called reachable from an iterator i if and only if there is a
finite sequence of applications of the expression ++i that makes i == j. If j
is reachable from i, they refer to elements of the same sequence.

A range is a pair of iterators that designate the beginning and end of the
computation. A range [i, i) is an empty range; in general, a range [i, j)
refers to the elements in the data structure starting with the element pointed
to by i and up to but not including the element pointed to by j.

Range [i, j) is valid if and only if j is reachable from i.
</quote>

Here there is no finite sequences of applications of the expression ++i that
makes i == j because running ++i will invoke undefined behavior far before i ==
j.  Thus this range is invalid.

And:

<quote>
The result of the application of functions in the standard library to invalid
ranges is undefined.
</quote>

Reply via email to