The following Fortran program (minimum working example) gives an erroneous array reference out of bounds warning: program test implicit none integer :: i,iarr(10) do i=1,10 if(i.gt.1) iarr(i-1) = i end do end program test $ gfortran -Wdo-subscript test.f90 -o test test.f90:5:21: do i=1,10 2 if(i.gt.1) iarr(i-1) = i 1 Warning: Array reference at (1) out of bounds (0 < 1) in loop beginning at (2) [-Wdo-subscript]
According to the docs: -Wdo-subscript Warn if an array subscript inside a DO loop could lead to an out-of-bounds access even if the compiler can not prove that the statement is actually executed, in cases like real a(3) do i=1,4 if (condition(i)) then a(i) = 1.2 end if end do This option is implied by -Wextra. Solution: Do not use the option unless you want it to do what it says. Currently, we do not have error supressing pragmas, this would be an even better method.