This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] PR43832 OPEN statement not diagnosing missing unit number


Hi folks,

The attached patch adds an error message. I also found a redundant and bad test case fgetc_3.f90 that failed with this patch and so I deleted it and added the new test case open_nounit.f90.

Regression tested on x86-64.

OK for trunk?

Regards,

Jerry

2010-04-24 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR fortran/43832
	* io.c (gfc_match_open): Remove branch to syntax error. Add call to
	gfc_error with new error message.
Index: testsuite/gfortran.dg/open_nounit.f90
===================================================================
--- testsuite/gfortran.dg/open_nounit.f90	(revision 0)
+++ testsuite/gfortran.dg/open_nounit.f90	(revision 0)
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR43832 Missing UNIT in OPEN
+  open () ! { dg-error "must have UNIT" }
+  open (file="test") ! { dg-error "must have UNIT" }
+  end
+
Index: testsuite/gfortran.dg/fgetc_3.f90
===================================================================
--- testsuite/gfortran.dg/fgetc_3.f90	(revision 158397)
+++ testsuite/gfortran.dg/fgetc_3.f90	(working copy)
@@ -1,34 +0,0 @@
-! Testcase for the FGETC and FPUTC intrinsics
-! { dg-do compile }
-  character(len=5) s
-  integer st
-
-  s = "12345"
-  open(status="scratch")
-  write(*,"(A)") "abcde"
-  rewind(10)
-  st = fget(s)
-  if ((st /= 0) .or. (s /= "a    ")) call abort
-  st = fget(s)
-  close(10)
-
-  open(status="scratch")
-  s = "12345"
-  st = fput(s)
-  if (st /= 0) call abort
-  st = fput("2")
-  if (st /= 0) call abort
-  st = fput("3 ")
-  if (st /= 0) call abort
-  rewind(10)
-  st = fget(s)
-  if (s(1:1) /= "1") call abort
-  st = fget(s)
-  if (s(1:1) /= "2") call abort
-  st = fget(s)
-  if ((s(1:1) /= "3") .or. (st /= 0)) call abort
-  st = fget(s)
-  if (st /= -1) call abort
-  close (10)
-
-  end
Index: fortran/io.c
===================================================================
--- fortran/io.c	(revision 158397)
+++ fortran/io.c	(working copy)
@@ -1771,8 +1771,6 @@ gfc_match_open (void)
   if (m == MATCH_NO)
     {
       m = gfc_match_expr (&open->unit);
-      if (m == MATCH_NO)
-	goto syntax;
       if (m == MATCH_ERROR)
 	goto cleanup;
     }
@@ -1820,6 +1818,11 @@ gfc_match_open (void)
 	  goto cleanup;
 	}
     }
+  else if (!open->unit)
+    {
+      gfc_error ("OPEN statement at %C must have UNIT or NEWUNIT specified");
+      goto cleanup;
+    }
 
   /* Checks on the ACCESS specifier.  */
   if (open->access && open->access->expr_type == EXPR_CONSTANT)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]