https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100954

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-10-01
          Component|fortran                     |libfortran

--- Comment #3 from anlauf at gcc dot gnu.org ---
This is possibly a bookkeeping issue.

Reduced testcase:

program inquire
  implicit none
  integer      :: iounit, ierr
  logical      :: opened
  character(4) :: c
! open(newunit=iounit,file="testfile")
  write(c,'(a)') "abcd"
  iounit = -10
  inquire(iounit, opened=opened,iostat=ierr)
  print *,iounit,'open?',opened,ierr
  iounit = -11
  inquire(iounit, opened=opened,iostat=ierr)
  print *,iounit,'open?',opened,ierr
endprogram inquire

This prints

         -10 open? T           0
         -11 open? F           0

but should print

         -10 open? F           0
         -11 open? F           0

Note that the start value -10 comes from unit.c:

#define NEWUNIT_START -10

If we uncomment before the internal write

  open(newunit=iounit,file="testfile")

then we'll find that units -10 and -11 are opened:

         -10 open? T           0
         -11 open? T           0

If we swap the open and internal write, then -11 is not opened:

         -10 open? T           0
         -11 open? F           0

Reply via email to