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?)
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 )
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: "126.96.36.199 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.)