https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66974
--- Comment #2 from Ganesh Ajjanagadde <gajjanagadde at gmail dot com> --- Of course. However, the caller might ensure that order is always in the valid range (e.g <= 3 in this case), and the callee should not have to verify this if that is the case. The reason we do not actually do the check is because it is in performance critical code (note test case is simplified and does not convey how critical it is, which can only be seen from interactions with larger codebase). As per manual, ----------------------- -Warray-bounds -Warray-bounds=n This option is only active when -ftree-vrp is active (default for -O2 and above). It warns about subscripts to arrays that are always out of bounds. This warning is enabled by -Wall. -Warray-bounds=1 This is the warning level of -Warray-bounds and is enabled by -Wall; higher levels are not, and must be explicitly requested. -Warray-bounds=2 This warning level also warns about out of bounds access for arrays at the end of a struct and for arrays accessed through pointers. This warning level may give a larger number of false positives and is deactivated by default. -------------------------- Thus, -Warray-bounds should not flag unless the compiler is certain about the out of bounds nature. Here the compiler can't do that, and should not give a false positive. For the sake of argument, suppose it should flag this. Then -Warray-bounds is not terribly useful, since much simpler code (below) does not trigger the warning under same flags: ------------------ int foo(unsigned order) { int c[3] = {1, 2, 3}; unsigned i; for (i=1; i < order; i++) c[i] += c[i/2]; return c[0]; } ------------------