Currently, we ignore the following: $ cat unformatted_stream_backspace.f90 program main open(2003,form="unformatted",access="stream") write (2003) 1 write (2003) 2 backspace 2003 end program main $ gfortran unformatted_stream_backspace.f90 $ ./a.out $ This code is actually illegal, we could (but are not required to) catch this: F 2003 draft, 9.7: A file that is connected for unformatted stream access shall not be referred to by a BACKSPACE statement.
Same thing for direct access and BACKSPACE, ENDFILE and REWIND.
I think a runtime error would be appropriate.
Subject: Bug 34405 Author: tkoenig Date: Thu Dec 13 19:35:09 2007 New Revision: 130912 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130912 Log: 2007-12-13 Thomas Koenig <tkoenig@gcc.gnu.org> PR libfortran/34370 PR libfortran/34323 PR libfortran/34405 * io/io.h: Add previous_nonadvancing_write to gfc_unit. Add prototype for finish_last_advance_record. * io/file_pos.c (st_backspace): Generate error if backspace is attempted for direct access or unformatted stream. If there are bytes left from a previous ADVANCE="no", write them out before performing the backspace. (st_endfile): Generate error if endfile is attempted for direct access. If there are bytes left from a previous ADVANCE="no", write them out before performing the endfile. (st_rewind): Generate error if rewind is attempted for direct access. * unit.c (close_unit_1): Move functionality to write previously written bytes to... (finish_last_advance_record): ... here. * transfer.c (data_transfer_init): If reading, reset previous_nonadvancing_write. (finalize_transfer): Set the previous_noadvancing_write flag if we are writing and ADVANCE="no" was specified. Only call next_record() if advance="no" wasn't specified. 2007-12-13 Thomas Koenig <tkoenig@gcc.gnu.org> PR libfortran/34370 PR libfortran/34323 PR libfortran/34405 * gfortran.dg/advance_6.f90: New test case. * gfortran.dg/direct_io_7.f90: New test case. * gfortran.dg/streamio_13.f90: New test case. Added: trunk/gcc/testsuite/gfortran.dg/advance_6.f90 trunk/gcc/testsuite/gfortran.dg/direct_io_7.f90 trunk/gcc/testsuite/gfortran.dg/streamio_13.f90 Modified: trunk/gcc/testsuite/ChangeLog trunk/libgfortran/ChangeLog trunk/libgfortran/io/file_pos.c trunk/libgfortran/io/io.h trunk/libgfortran/io/transfer.c trunk/libgfortran/io/unit.c
Fixed on trunk. Closing.