This program is based on a failing test of the Unicomp Fortran 95 test suite; while not all tests are correct (I found one which is listed as invalid code in the Fortran 2003 standard, which fails in gfortran), I think the following is valid. The problem is that gfortran sets the variable "is" to zero before it transfers the data. In "9.5.3 Execution of a data transfer input/output statement" one finds: "[...] (6) Transfer data between the file and the entities specified by the input/output list (if any) or namelist. (7) Determine whether an error, end-of-file, or end-of-record condition has occurred." The following program works with f95, ifort, sunf95 and openf95; it fails with gfortran and g95. program io_test implicit none integer :: is character(len=20) :: str is = 99 write (str, fmt=*, iostat=is) is print *, is print *, str if (is /= 0) stop 'FAIL 1' if (adjustl(str) /= '99') stop 'FAIL 2' end program io_test
This is invalid (but we could catch it, as an enhancement). From the F95 draft, 9.4.1: In a data transfer statement, the variable specified in an IOSTAT= or a SIZE= specifier, if any, shall not be associated with any entity in the data transfer input/output list (9.4.2) or namelist-group-object-list, nor with a do-variable of an io-implied-do in the data transfer input/output list.
> This is invalid (but we could catch it, as an enhancement). I somehow missed that clause. I think one can thus close this bug. The test suite seems to have more bugs than I hoped. (Though, having it fixed has the advantage that the Unicomp test suite passes ;-)
(In reply to comment #2) > I somehow missed that clause. I think one can thus close this bug. Finally doing so. Please re-open if new information was obtained in the meantime.