------- Comment #1 from burnus at gcc dot gnu dot org  2007-11-24 13:12 -------
Well, C is not Fortran and this program is INVALID. The invalidity is very hard
to detect at compile time and gfortran currently does not have an option to do
so at run time.

If you need to change the variable in the loop, you can do something like the
following:

loop = 1
do
  if (loop > 3) exit
  ...
  loop = loop + 1
end do

>From the Fortran 2003 standard:

"8.1.6.4.2 The execution cycle"
"The execution cycle of a DO construct consists of the following steps
performed in sequence repeatedly until termination: [...]
(3) The iteration count, if any, is decremented by one. The DO variable, if
any, is incremented by the value of the incrementation parameter m3.

Except for the incrementation of the DO variable that occurs in step (3), the
DO variable shall neither be redefined nor become undefined while the DO
construct is active."

You are violating the last constrain.

Notes:
- The compiler does (as it can be seen) certain optimizations based on that
contrain
- Such a constrain does not exist in C
- If the DO variable is directly modified (and not through a subroutine) or if
the interface of the subroutine is known to the compiler and INTENT(OUT) or
INTENT(INOUT) is specified, the compiler gives an error message.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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

Reply via email to