From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5779 invoked by alias); 16 Dec 2011 21:31:26 -0000 Received: (qmail 5771 invoked by uid 22791); 16 Dec 2011 21:31:26 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 16 Dec 2011 21:31:12 +0000 From: "w6ws at earthlink dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51589] New: Modification of loop index variable by intent(out) or intent(inout) procedures Date: Fri, 16 Dec 2011 21:33:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: w6ws at earthlink dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-12/txt/msg01879.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: w6ws@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$