https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124882
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #6)
> I was not able to find out if char_traits::find is similar in that aspect,
The effects of std::char_traits::find(p, n, c) are specified in terms of
[p,p+n) and that has an implicit requirement that [p,p+n) is a valid range,
which means p+n must be reachable from p. If p+n overflows a pointer, or if p
does not point to an array of n elements, then it's an invalid range and so
undefined.
> but if so, then char_traits<char>::find ("foobar", (size_t)-1, 'a') would
> both be well-defined and trigger the branch.
The warning doesn't say your code is undefined or ill-formed, it just says that
-1zu is larger than the largest possible object, which GCC considers to be
dubious and worth warning about.