https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90563
Bug ID: 90563 Summary: Out of bounds error when compiling with -Wextra Product: gcc Version: 8.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: m...@tobias-neumann.eu Target Milestone: --- The following program fails to compile with gfortran 8 and 9 (not with 7 and below) when compiling with -Wextra. -Wextra is supposed to only enable additional warnings, not enable new errors. I also can't see additional bounds checks in the additional warnings that are enabled with extra: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html % gfortran9 -Wextra -o test ./bcheck.f90 [14:20:23] ./bcheck.f90:11:28: 11 | p(j) = p(swap(j)) | 1 Error: Index in dimension 1 is out of bounds at (1) ./bcheck.f90:11:28: 9 | do j=1,6 | 2 10 | if (j<5) then 11 | p(j) = p(swap(j)) | 1 Warning: Array reference at (1) out of bounds (6 > 4) in loop beginning at (2) [-Wdo-subscript] Obviously the compiler is not clever enough to take into account the constraint from the if, but I don't think this should throw an error with -Wextra. program test implicit none integer, parameter :: swap(4) = [2,1,3,4] real :: p(20) integer :: j p = 0.0 do j=1,6 if (j<5) then p(j) = p(swap(j)) endif enddo end program