https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92539
Bug ID: 92539 Summary: [8/9/10 Regression] -Warray-bounds false positive (loop unroll?) Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nok.raven at gmail dot com Target Milestone: --- static bool ischar(int ch) { return (0 == (ch & ~0xff) || ~0 == (ch | 0xff)) != 0; } static bool eat(char const*& first, char const* last) { if (first != last && ischar(*first)) { ++first; return true; } return false; } static bool eat_two(char const*& first, char const* last) { auto save = first; if (eat(first, last) && eat(first, last)) return true; first = save; return false; } static bool foo(char const*& first, char const* last) { auto local_iterator = first; int i = 0; for (; i < 3; ++i) if (!eat_two(local_iterator, last)) return false; first = local_iterator; return true; } static bool test(char const* in, bool full_match = true) { auto last = in; while (*last) ++last; return foo(in, last) && (!full_match || (in == last)); } int main() { return test("aa"); } $ g++ -std=c++17 -O3 -Wall <source>: In function 'int main()': <source>:9:23: warning: array subscript 4 is outside array bounds of 'const char [3]' [-Warray-bounds] 9 | if (first != last && ischar(*first)) { | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ <source>:9:23: warning: array subscript 5 is outside array bounds of 'const char [3]' [-Warray-bounds] 9 | if (first != last && ischar(*first)) { | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ <source>:41:42: warning: array subscript 6 is outside array bounds of 'const char [3]' [-Warray-bounds] 41 | return foo(in, last) && (!full_match || (in == last)); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ https://godbolt.org/z/86XVfe The code is reduced Spirit.X3 test. The -fsanitize=address and -fsanitize=undefined do not show any errors.