Fix FLUSH IOSTAT value
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Thu, 16 Dec 2021 14:33:17 +0000 (15:33 +0100)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Thu, 16 Dec 2021 16:46:28 +0000 (17:46 +0100)
PR libfortran/101255

libgfortran/ChangeLog:

* io/file_pos.c: Fix error code.

gcc/testsuite/ChangeLog:

* gfortran.dg/iostat_5.f90: New file.

gcc/testsuite/gfortran.dg/iostat_5.f90 [new file with mode: 0644]
libgfortran/io/file_pos.c

diff --git a/gcc/testsuite/gfortran.dg/iostat_5.f90 b/gcc/testsuite/gfortran.dg/iostat_5.f90
new file mode 100644 (file)
index 0000000..1e72dfd
--- /dev/null
@@ -0,0 +1,16 @@
+! PR libfortran/101255
+! { dg-do run }
+
+program test
+  use ISO_FORTRAN_ENV, only: IOSTAT_EOR, IOSTAT_END
+  implicit none
+  character(len=50) :: err
+  integer :: i
+
+  err = ""
+  flush(99, iostat=i, iomsg=err)
+
+  if (err == "") stop 1
+  if (i >= 0) stop 2
+  if (i == IOSTAT_EOR .or. i == IOSTAT_END) stop 3
+end
index 7e71ca5..4ed1698 100644 (file)
@@ -527,7 +527,7 @@ st_flush (st_parameter_filepos *fpp)
     }
   else
     /* FLUSH on unconnected unit is illegal: F95 std., 9.3.5. */ 
-    generate_error (&fpp->common, LIBERROR_BAD_OPTION,
+    generate_error (&fpp->common, -LIBERROR_BAD_UNIT,
                        "Specified UNIT in FLUSH is not connected");
 
   if (needs_unlock)