https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81581
Bug ID: 81581 Summary: runtime checks for DIM argument of intrinsic SUM missing Product: gcc Version: 7.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: janus at gcc dot gnu.org Target Milestone: --- Please consider this test case: program summation integer, dimension(1:10,1:10) :: arr integer :: i do i=1,10 arr(i,:) = i end do ! print *, sum(arr, 5) ! compile-time error: "not a valid dimension index" call print_sum(1) call print_sum(2) call print_sum(5) contains subroutine print_sum(d) integer, intent(in) :: d print *, sum(arr, d) end subroutine end The commented line correctly generates a compile-time error. However, when the DIM argument to SUM is not a compile-time constant, wrong values are accepted and the program runs without any error or warning, producing the output: 55 55 55 55 55 55 55 55 55 55 10 20 30 40 50 60 70 80 90 100 0 0 0 0 0 0 0 0 0 0 I guess one should implement a runtime check that is enabled by -fcheck=all. (One could possibly include it into -fcheck=bounds?)