-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Labels
Description
Consider the following code:
module m
type base
integer, pointer :: data(:)
end type
integer ioUnit
interface read(formatted)
subroutine formattedRead (dtv, unit, iotype, v_list, iostat, iomsg)
import base
class (base), intent(inout) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
end subroutine
end interface
end module
program fdtio055
use m
character(1000) dataStream
character(200) err
integer stat
type (base) :: b1
integer, pointer :: i2(:)
nullify (b1%data)
dataStream = '3, 3, 2 1'
read (dataStream, *, iostat=stat, iomsg=err) b1
!! verify b1%data
print*, b1%data
if (any(b1%data /= (/3,2,1/))) ERROR STOP 2
end
subroutine formattedRead (dtv, unit, iotype, v_list, iostat, iomsg)
use m, only:base, ioUnit
class (base), intent(inout) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
integer dataSize, stat1
ioUnit = unit
if (associated (dtv%data)) then
deallocate (dtv%data, stat=stat1)
end if
read (unit, *, iostat=iostat, iomsg=iomsg) dataSize
if (iostat /= 0) return
if (dataSize <= 0) return
allocate (dtv%data(dataSize))
read (unit, *, iostat=iostat, iomsg=iomsg) dtv%data
end subroutine
Flang outputs
> a.out
0 3 2
Fortran ERROR STOP: code 2
All ifort, gfortran and XLF outputs
> a.out
3 2 1