[Bug fortran/78881] New: [F03] reading from string with DTIO procedure does not work properly
janus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Dec 21 11:06:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78881
Bug ID: 78881
Summary: [F03] reading from string with DTIO procedure does not
work properly
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: janus at gcc dot gnu.org
Target Milestone: ---
From
https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/706063:
module t_m
use, intrinsic :: iso_fortran_env, only : iostat_end, iostat_eor,
output_unit
implicit none
private
type, public :: t
private
character(len=:), allocatable :: m_s
contains
!private
procedure, pass(this), private :: read_t
generic :: read(formatted) => read_t
end type t
contains
subroutine read_t(this, lun, iotype, vlist, istat, imsg)
! argument definitions
class(t), intent(inout) :: this
integer, intent(in) :: lun
character(len=*), intent(in) :: iotype
integer, intent(in) :: vlist(:)
integer, intent(out) :: istat
character(len=*), intent(inout) :: imsg
!.. Local variables
character(len=*), parameter :: sfmt = "(*(g0))"
character(len=1) :: c
integer :: i
i = 0
loop_read: do
i = i + 1
read( unit=lun, fmt="(a)", iostat=istat, iomsg=imsg ) c
select case ( istat )
case ( 0 )
write( output_unit, fmt=sfmt) "i = ", i, ", c = ", c
case ( iostat_end )
write( output_unit, fmt=sfmt) "i = ", i, ", istat = iostat_end"
exit loop_read
case ( iostat_eor )
write( output_unit, fmt=sfmt) "i = ", i, ", istat = iostat_eor"
exit loop_read
case default
write( output_unit, fmt=sfmt) "i = ", i, ", istat = ", istat
exit loop_read
end select
end do loop_read
return
end subroutine read_t
end module t_m
program p
use t_m, only : t
implicit none
character(len=:), allocatable :: s
type(t) :: foo
character(len=256) :: imsg
integer :: istat
s = "Hello"
read( unit=s, fmt=*, iostat=istat, iomsg=imsg ) foo
if ( istat /= 0 ) then
print *, "istat = ", istat
print *, imsg
end if
stop
end program p
After compiling this with current trunk, the runtime output is:
i = 1, c = e
i = 2, c = l
i = 3, c = l
i = 4, c = o
i = 5, istat = iostat_end
istat = -1
End of file
It seems like the first character is being swallowed somewhere ...
More information about the Gcc-bugs
mailing list