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

--- Comment #6 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> This function is performance critical,

I can understand that, though I'd expect the bit that actually iterates to be
performance critical.

> adding a branch to deal with a
> condition that's impossible in correct code doesn't seem desirable.
> 

As pointed out in PR124905, it's well-defined to do:
...
memchr ("foobar", 'a', (size_t)-1)
...

I was not able to find out if char_traits::find is similar in that aspect, but
if so, then char_traits<char>::find ("foobar", (size_t)-1, 'a') would both be
well-defined and trigger the branch.

> Maybe __n &= __PTRDIFF_MAX__ would be better, although still redundant in
> correct code.

Agreed.

Reply via email to