]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2007-03-18 Jerry DeLisle <jvdelisle@gcc.gnu.org>
authorjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 18 Mar 2007 18:17:24 +0000 (18:17 +0000)
committerjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 18 Mar 2007 18:17:24 +0000 (18:17 +0000)
PR libgfortran/31052
* gfortran.dg/namelist_27.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123039 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/namelist_27.f90 [new file with mode: 0644]

index 51540e3e8de670871a6e7ba19dd12ee06c6b1af3..8e36820aa5e44bcc74989339d062b567f20dacf7 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/31052
+       * gfortran.dg/namelist_27.f90: New test.
+
 2007-03-18  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/30531
diff --git a/gcc/testsuite/gfortran.dg/namelist_27.f90 b/gcc/testsuite/gfortran.dg/namelist_27.f90
new file mode 100644 (file)
index 0000000..10b0031
--- /dev/null
@@ -0,0 +1,106 @@
+! { dg-do run }
+! PR31052 Bad IOSTAT values when readings NAMELISTs past EOF.
+! Patch derived from PR, submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>
+program gfcbug61
+  implicit none
+  integer            :: stat
+
+  open (12, status="scratch")
+  write (12, '(a)')"!================"
+  write (12, '(a)')"! Namelist REPORT"
+  write (12, '(a)')"!================"
+  write (12, '(a)')" &REPORT type     = 'SYNOP' "
+  write (12, '(a)')"         use      = 'active'"
+  write (12, '(a)')"         max_proc = 20"
+  write (12, '(a)')" /"
+  write (12, '(a)')"! Other namelists..."
+  write (12, '(a)')" &OTHER  i = 1 /"
+  rewind (12)
+
+  ! Read /REPORT/ the first time
+  rewind (12)
+  call position_nml (12, "REPORT", stat)
+  if (stat.ne.0) call abort()
+  if (stat == 0)  call read_report (12, stat)
+
+  ! Comment out the following lines to hide the bug
+  rewind (12)
+  call position_nml (12, "MISSING", stat)
+  if (stat.ne.-1)  call abort ()
+
+  ! Read /REPORT/ again
+  rewind (12)
+  call position_nml (12, "REPORT", stat)
+  if (stat.ne.0)  call abort()
+
+contains
+
+  subroutine position_nml (unit, name, status)
+    ! Check for presence of namelist 'name'
+    integer                      :: unit, status
+    character(len=*), intent(in) :: name
+
+    character(len=255) :: line
+    integer            :: ios, idx
+    logical            :: first
+
+    first = .true.
+    status = 0
+    ios = 0
+    line = ""
+    do
+       read (unit,'(a)',iostat=ios) line
+       if (first) then
+          first = .false.
+       end if
+       if (ios < 0) then
+          ! EOF encountered!
+          backspace (unit)
+          status = -1
+          return
+       else if (ios > 0) then
+          ! Error encountered!
+          status = +1
+          return
+       end if
+       idx = index (line, "&"//trim (name))
+       if (idx > 0) then
+          backspace (unit)
+          return
+       end if
+    end do
+  end subroutine position_nml
+
+  subroutine read_report (unit, status)
+    integer :: unit, status
+
+    integer            :: iuse, ios
+    !------------------
+    ! Namelist 'REPORT'
+    !------------------
+    character(len=12) :: type, use
+    integer           :: max_proc
+    namelist /REPORT/ type, use, max_proc
+    !-------------------------------------
+    ! Loop to read namelist multiple times
+    !-------------------------------------
+    iuse = 0
+    do
+       !----------------------------------------
+       ! Preset namelist variables with defaults
+       !----------------------------------------
+       type      = ''
+       use       = ''
+       max_proc  = -1
+       !--------------
+       ! Read namelist
+       !--------------
+       read (unit, nml=REPORT, iostat=ios)
+       if (ios /= 0) exit
+       iuse = iuse + 1
+    end do
+    if (iuse.ne.1) call abort()
+    status = ios
+  end subroutine read_report
+
+end program gfcbug61
\ No newline at end of file