]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Revise a namelist test case.
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 12 May 2023 20:38:25 +0000 (13:38 -0700)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 12 May 2023 20:40:42 +0000 (13:40 -0700)
PR fortran/109662

gcc/testsuite/ChangeLog:

* gfortran.dg/pr109662-a.f90: Add a section to verify that
a short namelist read does not modify the variable.

gcc/testsuite/gfortran.dg/pr109662-a.f90

index 0059df28b9f3840393518365697c74e866bd1d40..dc05d6b7a80a185982790e8cc496c23cb224b0e4 100644 (file)
@@ -3,13 +3,26 @@
 ! PR109662-a semi-colon after namelist name accepted on input. 
 program testnmlread
   implicit none
-  character(16) :: list = '&stuff; n = 759/'
+  character(16) :: line = '&stuff; n = 759/'
   character(100)::message
-  integer       :: n, ioresult
+  integer       :: n, i, ioresult
   namelist/stuff/n
   message = ""
   ioresult = 0
   n = 99
-  read(list,nml=stuff,iostat=ioresult)
-  if (ioresult == 0) STOP 13
+  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