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

            Bug ID: 95476
           Summary: Reading file of length zero
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.diehl at mpie dot de
  Target Milestone: ---

There is some ambiguity when reading a file of zero length:

program test

 character(len=:), allocatable :: a
 a = IO_read('empty.txt')

 print*, len(a)
 print*, '#'//a//'#'

contains

function IO_read(fileName) result(fileContent)

  character(len=*),  intent(in) :: fileName
  character(len=:), allocatable :: fileContent
  integer ::  &
    fileLength, &
    fileUnit, &
    myStat

  inquire(file = fileName, size=fileLength)
  open(newunit=fileUnit, file=fileName, access='stream',&
       status='old', position='rewind', action='read',iostat=myStat)
  if(myStat /= 0) stop 1
  allocate(character(len=fileLength)::fileContent)
  read(fileUnit,iostat=myStat) fileContent
  print*, mystat
  close(fileUnit)

end function IO_read

end program test

see also the discussion on 
https://software.intel.com/en-us/comment/1960049#comment-1960049

Reply via email to