Bug 34599 - IOSTAT variable in data transfer input/output list
Summary: IOSTAT variable in data transfer input/output list
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2007-12-27 15:24 UTC by Tobias Burnus
Modified: 2010-05-01 20:44 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-12-27 16:20:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-12-27 15:24:08 UTC
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
Comment 1 Thomas Koenig 2007-12-27 16:20:25 UTC
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.
Comment 2 Tobias Burnus 2007-12-27 19:14:58 UTC
> 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 ;-)
Comment 3 Daniel Franke 2010-05-01 20:44:26 UTC
(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.