http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51589

             Bug #: 51589
           Summary: Modification of loop index variable by intent(out) or
                    intent(inout) procedures
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: w...@earthlink.net


In the following snippet of code, the loop index variable is passed to
procedures via either intent(out) or intent(inout) dummy arguments.  In the
first of these cases, intent(out), gfortran should give a "Variable 'i' at (1)
cannot be redefined inside loop" error but does not.  Even with --pedantic.  It
is arguable whether the second should give the same error, or just a warning.

Note that Intel 12.1 gives warnings for both usages.  The resulting code only
runs for one iteration.  With gfortran, it ends up in an infinite loop.

wws@w6ws-4:~/fortran/intents$ cat intents.f90
program intents
  implicit none

  integer :: i

  do, i=1,10
    call sub1 (i)
    print *, i
    call sub2 (i)
    print *, i
  end do

contains

  subroutine sub1 (idx)
    integer, intent(inout) :: idx

    idx = 42

  end subroutine

  subroutine sub2 (idx)
    integer, intent(out) :: idx

    idx = 11

  end subroutine

end program
wws@w6ws-4:~/fortran/intents$ gfortran --pedantic intents.f90
wws@w6ws-4:~/fortran/intents$ gfortran --version
GNU Fortran (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

wws@w6ws-4:~/fortran/intents$

Reply via email to