aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry DeLisle <jvdelisle@gcc.gnu.org>2007-04-01 17:33:13 +0000
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2007-04-01 17:33:13 +0000
commita616b1da79fa53234feb3367578720f0d6573cdc (patch)
tree124e47d6539a871f893d7ecce76be7243aeb0750
parent08f9246a4574b9882c67bc64fabc69817142948f (diff)
downloadgcc-a616b1da79fa53234feb3367578720f0d6573cdc.zip
gcc-a616b1da79fa53234feb3367578720f0d6573cdc.tar.gz
gcc-a616b1da79fa53234feb3367578720f0d6573cdc.tar.bz2
re PR libfortran/31052 ([4.2 only] Bad IOSTAT values when readings NAMELISTs past EOF)
2007-04-01 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/31052 * gfortran.dg/namelist_28.f90: New test. From-SVN: r123404
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/namelist_28.f9090
2 files changed, 95 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c04ae81..3b4d65a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2007-04-01 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+ PR libgfortran/31052
+ * gfortran.dg/namelist_28.f90: New test.
+
+2007-04-01 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
PR libgfortran/31366
* gfortran.dg/direct_io_6.f90: New test.
diff --git a/gcc/testsuite/gfortran.dg/namelist_28.f90 b/gcc/testsuite/gfortran.dg/namelist_28.f90
new file mode 100644
index 0000000..53b1f0f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/namelist_28.f90
@@ -0,0 +1,90 @@
+! { 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, parameter :: nmlunit = 12 ! Namelist unit
+ integer :: stat
+
+ open (nmlunit, status="scratch")
+ write(nmlunit, '(a)') "&REPORT type='report1' /"
+ write(nmlunit, '(a)') "&REPORT type='report2' /"
+ write(nmlunit, '(a)') "!"
+ rewind (nmlunit)
+
+! The call to position_nml is contained in the subroutine
+ call read_report (nmlunit, stat)
+ rewind (nmlunit)
+ call position_nml (nmlunit, 'MISSING', stat)
+ rewind (nmlunit)
+ call read_report (nmlunit, stat) ! gfortran fails here
+
+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
+ do
+ line = ""
+ read (unit,'(a)',iostat=ios) line
+ 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
+ namelist /REPORT/ type
+ !-------------------------------------
+ ! Loop to read namelist multiple times
+ !-------------------------------------
+ iuse = 0
+ do
+ !----------------------------------------
+ ! Preset namelist variables with defaults
+ !----------------------------------------
+ type = ''
+ !--------------
+ ! Read namelist
+ !--------------
+ call position_nml (unit, "REPORT", status)
+ if (stat /= 0) then
+ ios = status
+ if (iuse /= 2) call abort()
+ return
+ end if
+ read (unit, nml=REPORT, iostat=ios)
+ if (ios /= 0) exit
+ iuse = iuse + 1
+ end do
+ status = ios
+ end subroutine read_report
+
+end program gfcbug61