I plan to commit the following as simple.

The issue was a value was being modified on a short namelist read. After tthe first read gives the correct EOF, a second read would give the error but modify the variable.

diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c
index 82664dc5f98..36d025949c2 100644
--- a/libgfortran/io/unit.c
+++ b/libgfortran/io/unit.c
@@ -504,6 +504,7 @@ set_internal_unit (st_parameter_dt *dtp, gfc_unit *iunit, int kind)
   iunit->current_record=0;
   iunit->read_bad = 0;
   iunit->endfile = NO_ENDFILE;
+  iunit->last_char = 0;

   /* Set flags for the internal unit.  */


The revised test case attached.  It has been regression tested OK.

Regards,

Jerry
! { dg-do run }
! { dg-options "-std=f2003" }
! PR109662-a semi-colon after namelist name accepted on input. 
program testnmlread
  implicit none
  character(16) :: line = '&stuff; n = 759/'
  character(100)::message
  integer       :: n, i, ioresult
  namelist/stuff/n
  message = ""
  ioresult = 0
  n = 99
  read(line,nml=stuff,iostat=ioresult)
  if (ioresult == 0) STOP 13 ! Should error with the semi-colon in there.

  ! Intentional short input (-> EOF)
  line = "&stuff"
  ! Problem manifests on two bad reads on same string.
  do i = 1, 6
    n = -1
    ioresult = 0

    read (line,nml=stuff,iostat=ioresult)
    if (n /= -1) STOP 24
    if (ioresult == 0) STOP 25
  end do

end program testnmlread

Reply via email to