Bug ID: 84529
           Summary: INQUIRE fails on "recycled" internal units
           Product: gcc
           Version: 7.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot
          Reporter: albandil at atlas dot cz
  Target Milestone: ---

The following program fails with the error "Inquire statement identifies an
internal file" at the call to INQUIRE.

  program TestRecycleInternalUnit

    implicit none

    integer :: iunit, ipos
    character(len=10) :: sstream

    write(sstream,'(I0)') 12345
    print *, 'sstream = ', sstream

    open(newunit=iunit, file='output.bin', access="stream", form="unformatted")
    print *, 'n = ', ipos

  end program TestRecycleInternalUnit

I looked into the code of libgfortran/io/open.c (and around) and it seems that
OPEN reuses the cached internal unit (-10 in this case) used for writing to
string. However, the member "internal_unit_kind" of the unit structure is not
reset to 0 in the "st_open" function. This makes the subsequent INQUIRE think
that its argument is an internal unit.

Reply via email to