https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88776
Bug ID: 88776 Summary: Namelist read from stdin: loss of data Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: anlauf at gmx dot de Target Milestone: --- Reading namelist from unit 5 may skip valid data later when an error is encountered. This problem does not occur when another unit number is used. Example: % cat gfcbug154.f90 program nmlbug implicit none integer :: i, stat, nnml nnml = 5 ! No problem with nnml = 10 ! nnml = 10 open (nnml, file="gfcbug154.dat", action="read") do i = 1, 3 print *, "# Read namelist", i call read_nml_type_2 print * end do contains subroutine read_nml_type_2 !---------------------------------------------------------- ! variant 2 of namelist input: chan = real char(len=*) real !---------------------------------------------------------- type t_chan real :: ichan = -1. character(len=10) :: flag = '' real :: band = -1. end type t_chan type(t_chan) :: chan(2) namelist /CHAN_NML/ chan chan(:) = t_chan(-1.,'',-1.) stat = 0 read (nnml, nml=CHAN_NML, iostat=stat, end=99) print *, "read_nml_type_2: stat=", stat print *, "chan(1)=", chan(1) print *, "chan(2)=", chan(2) return 99 stop "EOF" end subroutine read_nml_type_2 end program nmlbug % cat gfcbug154.dat &CHAN_NML chan = 3 '#1 ' '0.1' 6 '#1 ' 0.8 / &CHAN_NML chan = 4 '#2 ' 0.1 7 '#2 ' 0.2 / &CHAN_NML chan = 5 '#3 ' 0.3 8 '#3 ' 0.4 / The above code outputs: # Read namelist 1 read_nml_type_2: stat= 5010 chan(1)= 4.00000000 #2 0.100000001 chan(2)= 7.00000000 #2 0.200000003 # Read namelist 2 read_nml_type_2: stat= 0 chan(1)= 5.00000000 #3 0.300000012 chan(2)= 8.00000000 #3 0.400000006 # Read namelist 3 STOP EOF whereas with e.g. unit 10 it (correctly) outputs: # Read namelist 1 read_nml_type_2: stat= 5010 chan(1)= 3.00000000 #1 -1.00000000 chan(2)= -1.00000000 -1.00000000 # Read namelist 2 read_nml_type_2: stat= 0 chan(1)= 4.00000000 #2 0.100000001 chan(2)= 7.00000000 #2 0.200000003 # Read namelist 3 read_nml_type_2: stat= 0 chan(1)= 5.00000000 #3 0.300000012 chan(2)= 8.00000000 #3 0.400000006 For some reason, when an error is encountered during the first read, it correctly sets the error status, but apparently continues to the second namelist instance.