aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/namelist_28.f90
diff options
context:
space:
mode:
authorBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
committerBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
commit1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch)
treec607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/gcc/testsuite/gfortran.dg/namelist_28.f90
parent283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff)
downloadtoolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/gcc/testsuite/gfortran.dg/namelist_28.f90')
-rw-r--r--gcc-4.9/gcc/testsuite/gfortran.dg/namelist_28.f9092
1 files changed, 92 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/gfortran.dg/namelist_28.f90 b/gcc-4.9/gcc/testsuite/gfortran.dg/namelist_28.f90
new file mode 100644
index 000000000..22bddf662
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/gfortran.dg/namelist_28.f90
@@ -0,0 +1,92 @@
+! { 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, k
+ logical :: first
+
+ first = .true.
+ status = 0
+ do k=1,25
+ 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
+ if (k.gt.10) call abort
+ end subroutine position_nml
+
+ subroutine read_report (unit, status)
+ integer :: unit, status
+
+ integer :: iuse, ios, k
+ !------------------
+ ! Namelist 'REPORT'
+ !------------------
+ character(len=12) :: type
+ namelist /REPORT/ type
+ !-------------------------------------
+ ! Loop to read namelist multiple times
+ !-------------------------------------
+ iuse = 0
+ do k=1,25
+ !----------------------------------------
+ ! 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
+ if (k.gt.10) call abort
+ status = ios
+ end subroutine read_report
+
+end program gfcbug61