The Fortran 2003 standard declares:
"Every input/output statement except an OPEN, CLOSE, INQUIRE, or WAIT statement
shall refer to a unit that is connected to a file"

gfortran does not give a run-time error. However, I don't know whether one
should enforce the standard (and thus do this check).

program test
  write(*,*) 'Hello'
  flush(6) ! preconnected unit (stdout)
  flush(99)! preconnected unit
 ! flush()  ! invalid
  close(88) ! close preconnected unit <<<<<<<<
  close(88) ! close once more
  ! wait(88) ! not supported by gfortran
  flush(88) ! invalid    <<<<<<<<<<<<<
  write(88,*) 'This should also produce an error' !<<<<<<
end program test

Expected: Like NAG f95 (or g95)
 Hello
Unit 88 is not connected
Program terminated by fatal I/O error
In TEST, line 9 of flush.f90


-- 
           Summary: flush() / write() statement on closed units - error?
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tobias dot burnus at physik dot fu-berlin dot de


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

Reply via email to