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

            Bug ID: 65258
           Summary: Wrong array bounds warning
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: myrusmailacc at ru dot ru

Created attachment 34907
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34907&action=edit
main.c

http://coliru.stacked-crooked.com/a/cd5820f0371106dd

At least gcc and g++ 4.8.2 and 4.9.2 are affected

Source:

#include <stdio.h>

int main(){
    unsigned i, j, a[10] = {0};

    for (j = 23; j < 25; j++){
        for (i = j / 8; i --> 0;) a[i] = 0;
        for (i =     1; i --> 0;) printf("%u", a[i]);
    }

    return 0;
}

Output:
gcc -O3 -Wall -Wextra -pedantic main.cpp && ./a.out
main.cpp: In function 'int main()':
main.cpp:7:38: warning: array subscript is above array bounds [-Warray-bounds]
         for (i = j / 8; i --> 0;) a[i] = 0;
                                      ^

main.cpp:7:38: warning: array subscript is above array bounds [-Warray-bounds]
main.cpp:7:38: warning: array subscript is above array bounds [-Warray-bounds]
main.cpp:7:38: warning: array subscript is above array bounds [-Warray-bounds]
main.cpp:7:38: warning: array subscript is above array bounds [-Warray-bounds]
main.cpp:7:38: warning: array subscript is above array bounds [-Warray-bounds]
main.cpp:7:38: warning: array subscript is above array bounds [-Warray-bounds]

00

Reply via email to