re PR fortran/83057 (OPEN without a filename and without STATUS='SCRATCH' could produ...
authorHarald Anlauf <anlauf@gmx.de>
Fri, 22 Feb 2019 20:35:38 +0000 (20:35 +0000)
committerHarald Anlauf <anlauf@gcc.gnu.org>
Fri, 22 Feb 2019 20:35:38 +0000 (20:35 +0000)
2019-02-22  Harald Anlauf  <anlauf@gmx.de>

PR fortran/83057
* io.c (gfc_match_open): Fix logic in checks of OPEN statement
when NEWUNIT= is specified.

PR fortran/83057
* gfortran.dg/newunit_6.f90: New test.

From-SVN: r269134

gcc/fortran/ChangeLog
gcc/fortran/io.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/newunit_6.f90 [new file with mode: 0644]

index 970d1628ae80cb6b0a88d4fd3b8c1a1efe47d09f..4de649e25503e7a3ce0cbc0e3765651909cb5a3d 100644 (file)
@@ -1,3 +1,9 @@
+2019-02-22  Harald Anlauf  <anlauf@gmx.de>
+
+       PR fortran/83057
+       * io.c (gfc_match_open): Fix logic in checks of OPEN statement
+       when NEWUNIT= is specified.
+
 2019-02-22  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/89431
index 95b3013220350513d0727435d169b2f17bf256fc..9828897852a5e75f2e16823b3fc9145f35d1a39b 100644 (file)
@@ -2504,16 +2504,15 @@ gfc_match_open (void)
          goto cleanup;
        }
 
-      if (!open->file && open->status)
-        {
-         if (open->status->expr_type == EXPR_CONSTANT
+      if (!open->file &&
+         (!open->status ||
+          (open->status->expr_type == EXPR_CONSTANT
             && gfc_wide_strncasecmp (open->status->value.character.string,
-                                      "scratch", 7) != 0)
-          {
+                                     "scratch", 7) != 0)))
+       {
             gfc_error ("NEWUNIT specifier must have FILE= "
                        "or STATUS='scratch' at %C");
             goto cleanup;
-          }
        }
     }
   else if (!open->unit)
index 9fae9ffa169033f10aeb8241b37461188dc30f4f..dd0437780c848af71a642dc40e81956c19334f96 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-22  Harald Anlauf  <anlauf@gmx.de>
+
+       PR fortran/83057
+       * gfortran.dg/newunit_6.f90: New test.
+
 2019-02-22  Marek Polacek  <polacek@redhat.com>
 
        PR c++/89420 - ICE with CAST_EXPR in explicit-specifier.
diff --git a/gcc/testsuite/gfortran.dg/newunit_6.f90 b/gcc/testsuite/gfortran.dg/newunit_6.f90
new file mode 100644 (file)
index 0000000..849c792
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+!
+! PR fortran/83057 - OPEN without a filename and without STATUS='SCRATCH'
+!                    could produce a warning
+
+  open(newunit=iun,file="file")         ! this is ok
+  open(newunit=jun,status="scratch")    ! this too
+  open(newunit=lun)             ! { dg-error "NEWUNIT specifier must have" }
+end