Bug 52860 - I/O: gfortran rejects writing after hitting END=
Summary: I/O: gfortran rejects writing after hitting END=
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-04 07:50 UTC by Tobias Burnus
Modified: 2012-04-05 08:26 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-04-04 07:50:42 UTC
Reported by Christian Convey at http://gcc.gnu.org/ml/fortran/2012-03/msg00138.html

Note: I have not checked the standard whether the following program is valid, I just want to make sure that the email does not get lost. Please also answer the original reporter.


The following program reads from an empty file (created through the open statement) - it immediately hits an END - and then tries to write to that file.

That succeeds with:
  g77, g95, gfortran <= 4.4, pgf90, ifort

It fails with:
  gfortran >= 4.5, openf95, pathf95, crayftn
with the message:
  Fortran runtime error: Sequential READ or WRITE not allowed after EOF
  marker, possibly use REWIND or BACKSPACE

Please check whether that's indeed the proper error. (If so, should we add some legacy support?)


      PROGRAM MYTEST
       OPEN( UNIT=3, FILE='FOO', STATUS='UNKNOWN',
     1       FORM='FORMATTED', ACCESS='SEQUENTIAL', IOSTAT=IOS )
       write (*,*) 'reading'
       READ ( UNIT=3, FMT=*, END=10 )  BFR
       write (*,*) 'Done readin (no END)'
       GO TO 20
!    10  REWIND( UNIT=3 )
   10  write (*,*) 'Hit END - writing'
       WRITE( UNIT=3, FMT='(A16)' )  'BATCH MODE = OFF'
       write (*,*) 'Done writing'
   20  write (*,*) 'Really done - closing'
       CLOSE( UNIT=3 )
       END PROGRAM
Comment 1 Tobias Burnus 2012-04-05 08:26:57 UTC
Close as INVALID.

From Fortran 2008, "9.11.3 End-of-file condition and the END= specifier":

"If an end-of-file condition occurs during execution of an input/output statement that contains either an END= specifier or an IOSTAT= specifier, and an error condition does not occur then:
...
(4) if the file specified in the input statement is an external record file, it is positioned after the endfile record;"

And: "9.3.4.3 File position prior to data transfer"

"If the file contains an endfile record, the file shall not be positioned after the endfile record prior to data transfer. However, a REWIND or BACKSPACE statement may be used to reposition the file."

(Side note: FORTRAN 77 has nearly same words.)