https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89337
--- Comment #3 from Rafael Avila de Espindola <rafael at espindo dot la> ---
> GCC can't see that drop3() cannot be called with name.size() < 3, and in
> resize, the condition (n > size()) can only be true only when name.size() <
> 3 so n - size() is unavoidably too large.
That is why gcc should not warn about it :-)
The original testcase had
if (boost::algorithm::ends_with(name, "%2A")) {
name.resize(name.length() - 3);
I think it is fair to say that:
* The code is valid, if something ends with "%2A" the size is >= 3.
* GCC should not be required to figure out the above implication.
* The developer should not be required to add a __builtin_unreachable() to
avoid a warning in the above code.
I will re reduce the testcase keeping the ends_with and attach.