re PR fortran/21435 (fails to open nonexisting file with status scratch)
authorFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Fri, 13 Oct 2006 08:18:50 +0000 (08:18 +0000)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Fri, 13 Oct 2006 08:18:50 +0000 (08:18 +0000)
PR fortran/21435

* io.c (compare_to_allowed_values): New function.
(gfc_match_open): Add checks for constant values of specifiers.
(gfc_match_close): Add checks for constant values of the STATUS
specifier.

* gcc/testsuite/gfortran.dg/io_constraints_3.f90: New test.
* gcc/testsuite/gfortran.dg/open_access_append_1.f90: Add checks
for compile-time warnings.
* gcc/testsuite/gfortran.dg/pr20163-2.f: Likewise.
* gcc/testsuite/gfortran.dg/iostat_2.f90: Likewise.
* gcc/testsuite/gfortran.dg/label_4.f90: Delete the temporary
file.
* gcc/testsuite/gfortran.dg/direct_io_2.f90: Add a FILE=
specifier.
* gcc/testsuite/gfortran.dg/iomsg_1.f90: Add check for
compile-time warning.

From-SVN: r117685

gcc/fortran/ChangeLog
gcc/fortran/io.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/direct_io_2.f90
gcc/testsuite/gfortran.dg/io_constraints_3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/iomsg_1.f90
gcc/testsuite/gfortran.dg/iostat_2.f90
gcc/testsuite/gfortran.dg/label_4.f90
gcc/testsuite/gfortran.dg/open_access_append_1.f90
gcc/testsuite/gfortran.dg/pr20163-2.f

index 6f1006d2d0740d5ace181a1f1589b81bc2b57373..5d1365aa0ac862c793047efef6f24f4bb3f9a0fc 100644 (file)
@@ -1,3 +1,11 @@
+2006-10-13  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR fortran/21435
+       * io.c (compare_to_allowed_values): New function.
+       (gfc_match_open): Add checks for constant values of specifiers.
+       (gfc_match_close): Add checks for constant values of the STATUS
+       specifier.
+
 2006-10-12  Brooks Moses  <bmoses@stanford.edu>
 
        * intrinsic.texi (STAT): Fixed a format typo in sample code.
index a95cd2c8361b779c946270ef204f0db1f7348d9b..20bf26215d54e1968686ff188ff112c19e26602a 100644 (file)
@@ -1253,6 +1253,99 @@ gfc_resolve_open (gfc_open * open)
 }
 
 
+
+/* Check if a given value for a SPECIFIER is either in the list of values
+   allowed in F95 or F2003, issuing an error message and returning a zero
+   value if it is not allowed.  */
+static int
+compare_to_allowed_values (const char * specifier, const char * allowed[],
+                          const char * allowed_f2003[], 
+                          const char * allowed_gnu[], char * value,
+                          const char * statement, bool warn)
+{
+  int i;
+  unsigned int len;
+
+  len = strlen(value);
+  if (len > 0)
+  {
+    for (len--; len > 0; len--)
+      if (value[len] != ' ')
+       break;
+    len++;
+  }
+
+  for (i = 0; allowed[i]; i++)
+    if (len == strlen(allowed[i])
+       && strncasecmp (value, allowed[i], strlen(allowed[i])) == 0)
+      return 1;
+
+  for (i = 0; allowed_f2003 && allowed_f2003[i]; i++)
+    if (len == strlen(allowed_f2003[i])
+       && strncasecmp (value, allowed_f2003[i], strlen(allowed_f2003[i])) == 0)
+      {
+       notification n = gfc_notification_std (GFC_STD_F2003);
+
+       if (n == WARNING || (warn && n == ERROR))
+         {
+           gfc_warning ("Fortran 2003: %s specifier in %s statement at %C "
+                        "has value '%s'", specifier, statement,
+                        allowed_f2003[i]);
+           return 1;
+         }
+       else
+         if (n == ERROR)
+           {
+             gfc_notify_std (GFC_STD_F2003, "Fortran 2003: %s specifier in "
+                             "%s statement at %C has value '%s'", specifier,
+                             statement, allowed_f2003[i]);
+             return 0;
+           }
+
+       /* n == SILENT */
+       return 1;
+      }
+
+  for (i = 0; allowed_gnu && allowed_gnu[i]; i++)
+    if (len == strlen(allowed_gnu[i])
+       && strncasecmp (value, allowed_gnu[i], strlen(allowed_gnu[i])) == 0)
+      {
+       notification n = gfc_notification_std (GFC_STD_GNU);
+
+       if (n == WARNING || (warn && n == ERROR))
+         {
+           gfc_warning ("Extension: %s specifier in %s statement at %C "
+                        "has value '%s'", specifier, statement,
+                        allowed_gnu[i]);
+           return 1;
+         }
+       else
+         if (n == ERROR)
+           {
+             gfc_notify_std (GFC_STD_GNU, "Extension: %s specifier in "
+                             "%s statement at %C has value '%s'", specifier,
+                             statement, allowed_gnu[i]);
+             return 0;
+           }
+
+       /* n == SILENT */
+       return 1;
+      }
+
+  if (warn)
+    {
+      gfc_warning ("%s specifier in %s statement at %C has invalid value '%s'",
+                  specifier, statement, value);
+      return 1;
+    }
+  else
+    {
+      gfc_error ("%s specifier in %s statement at %C has invalid value '%s'",
+                specifier, statement, value);
+      return 0;
+    }
+}
+
 /* Match an OPEN statement.  */
 
 match
@@ -1260,6 +1353,7 @@ gfc_match_open (void)
 {
   gfc_open *open;
   match m;
+  bool warn;
 
   m = gfc_match_char ('(');
   if (m == MATCH_NO)
@@ -1303,6 +1397,240 @@ gfc_match_open (void)
       goto cleanup;
     }
 
+  warn = (open->err || open->iostat) ? true : false;
+  /* Checks on the ACCESS specifier.  */
+  if (open->access && open->access->expr_type == EXPR_CONSTANT)
+    {
+      static const char * access_f95[] = { "SEQUENTIAL", "DIRECT", NULL };
+      static const char * access_f2003[] = { "STREAM", NULL };
+      static const char * access_gnu[] = { "APPEND", NULL };
+
+      if (!compare_to_allowed_values ("ACCESS", access_f95, access_f2003,
+                                     access_gnu,
+                                     open->access->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    }
+
+  /* Checks on the ACTION specifier.  */
+  if (open->action && open->action->expr_type == EXPR_CONSTANT)
+    {
+      static const char * action[] = { "READ", "WRITE", "READWRITE", NULL };
+
+      if (!compare_to_allowed_values ("ACTION", action, NULL, NULL,
+                                     open->action->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    }
+
+  /* Checks on the ASYNCHRONOUS specifier.  */
+  /* TODO: code is ready, just needs uncommenting when async I/O support
+     is added ;-)
+  if (open->asynchronous && open->asynchronous->expr_type == EXPR_CONSTANT)
+    {
+      static const char * asynchronous[] = { "YES", "NO", NULL };
+
+      if (!compare_to_allowed_values
+               ("action", asynchronous, NULL, NULL,
+                open->asynchronous->value.character.string, "OPEN", warn))
+       goto cleanup;
+    }*/
+  
+  /* Checks on the BLANK specifier.  */
+  if (open->blank && open->blank->expr_type == EXPR_CONSTANT)
+    {
+      static const char * blank[] = { "ZERO", "NULL", NULL };
+
+      if (!compare_to_allowed_values ("BLANK", blank, NULL, NULL,
+                                     open->blank->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    }
+
+  /* Checks on the DECIMAL specifier.  */
+  /* TODO: uncomment this code when DECIMAL support is added 
+  if (open->decimal && open->decimal->expr_type == EXPR_CONSTANT)
+    {
+      static const char * decimal[] = { "COMMA", "POINT", NULL };
+
+      if (!compare_to_allowed_values ("DECIMAL", decimal, NULL, NULL,
+                                     open->decimal->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    } */
+
+  /* Checks on the DELIM specifier.  */
+  if (open->delim && open->delim->expr_type == EXPR_CONSTANT)
+    {
+      static const char * delim[] = { "APOSTROPHE", "QUOTE", "NONE", NULL };
+
+      if (!compare_to_allowed_values ("DELIM", delim, NULL, NULL,
+                                     open->delim->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    }
+
+  /* Checks on the ENCODING specifier.  */
+  /* TODO: uncomment this code when ENCODING support is added 
+  if (open->encoding && open->encoding->expr_type == EXPR_CONSTANT)
+    {
+      static const char * encoding[] = { "UTF-8", "DEFAULT", NULL };
+
+      if (!compare_to_allowed_values ("ENCODING", encoding, NULL, NULL,
+                                     open->encoding->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    } */
+
+  /* Checks on the FORM specifier.  */
+  if (open->form && open->form->expr_type == EXPR_CONSTANT)
+    {
+      static const char * form[] = { "FORMATTED", "UNFORMATTED", NULL };
+
+      if (!compare_to_allowed_values ("FORM", form, NULL, NULL,
+                                     open->form->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    }
+
+  /* Checks on the PAD specifier.  */
+  if (open->pad && open->pad->expr_type == EXPR_CONSTANT)
+    {
+      static const char * pad[] = { "YES", "NO", NULL };
+
+      if (!compare_to_allowed_values ("PAD", pad, NULL, NULL,
+                                     open->pad->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    }
+
+  /* Checks on the POSITION specifier.  */
+  if (open->position && open->position->expr_type == EXPR_CONSTANT)
+    {
+      static const char * position[] = { "ASIS", "REWIND", "APPEND", NULL };
+
+      if (!compare_to_allowed_values ("POSITION", position, NULL, NULL,
+                                     open->position->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    }
+
+  /* Checks on the ROUND specifier.  */
+  /* TODO: uncomment this code when ROUND support is added 
+  if (open->round && open->round->expr_type == EXPR_CONSTANT)
+    {
+      static const char * round[] = { "UP", "DOWN", "ZERO", "NEAREST",
+                                     "COMPATIBLE", "PROCESSOR_DEFINED", NULL };
+
+      if (!compare_to_allowed_values ("ROUND", round, NULL, NULL,
+                                     open->round->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    } */
+
+  /* Checks on the SIGN specifier.  */
+  /* TODO: uncomment this code when SIGN support is added 
+  if (open->sign && open->sign->expr_type == EXPR_CONSTANT)
+    {
+      static const char * sign[] = { "PLUS", "SUPPRESS", "PROCESSOR_DEFINED",
+                                    NULL };
+
+      if (!compare_to_allowed_values ("SIGN", sign, NULL, NULL,
+                                     open->sign->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+    } */
+
+#define warn_or_error(...) \
+{ \
+  if (warn) \
+    gfc_warning (__VA_ARGS__); \
+  else \
+    { \
+      gfc_error (__VA_ARGS__); \
+      goto cleanup; \
+    } \
+}
+
+  /* Checks on the RECL specifier.  */
+  if (open->recl && open->recl->expr_type == EXPR_CONSTANT
+      && open->recl->ts.type == BT_INTEGER
+      && mpz_sgn (open->recl->value.integer) != 1)
+    {
+      warn_or_error ("RECL in OPEN statement at %C must be positive");
+    }
+
+  /* Checks on the STATUS specifier.  */
+  if (open->status && open->status->expr_type == EXPR_CONSTANT)
+    {
+      static const char * status[] = { "OLD", "NEW", "SCRATCH",
+       "REPLACE", "UNKNOWN", NULL };
+
+      if (!compare_to_allowed_values ("STATUS", status, NULL, NULL,
+                                     open->status->value.character.string,
+                                     "OPEN", warn))
+       goto cleanup;
+
+      /* F2003, 9.4.5: If the STATUS= specifier has the value NEW or REPLACE,
+         the FILE= specifier shall appear.  */
+      if (open->file == NULL &&
+         (strncasecmp (open->status->value.character.string, "replace", 7) == 0
+         || strncasecmp (open->status->value.character.string, "new", 3) == 0))
+       {
+         warn_or_error ("The STATUS specified in OPEN statement at %C is '%s' "
+                        "and no FILE specifier is present",
+                        open->status->value.character.string);
+       }
+
+      /* F2003, 9.4.5: If the STATUS= specifier has the value SCRATCH,
+        the FILE= specifier shall not appear.  */
+      if (strncasecmp (open->status->value.character.string, "scratch", 7) == 0
+         && open->file)
+       {
+         warn_or_error ("The STATUS specified in OPEN statement at %C cannot "
+                        "have the value SCRATCH if a FILE specifier "
+                        "is present");
+       }
+    }
+
+  /* Things that are not allowed for unformatted I/O.  */
+  if (open->form && open->form->expr_type == EXPR_CONSTANT
+      && (open->delim
+         /* TODO uncomment this code when F2003 support is finished */
+         /* || open->decimal || open->encoding || open->round
+            || open->sign */
+         || open->pad || open->blank)
+      && strncasecmp (open->form->value.character.string,
+                     "unformatted", 11) == 0)
+    {
+      const char * spec = (open->delim ? "DELIM " : (open->pad ? "PAD " :
+           open->blank ? "BLANK " : ""));
+
+      warn_or_error ("%sspecifier at %C not allowed in OPEN statement for "
+                    "unformatted I/O", spec);
+    }
+
+  if (open->recl && open->access && open->access->expr_type == EXPR_CONSTANT
+      && strncasecmp (open->access->value.character.string, "stream", 6) == 0)
+    {
+      warn_or_error ("RECL specifier not allowed in OPEN statement at %C for "
+                    "stream I/O");
+    }
+
+  if (open->position && open->access && open->access->expr_type == EXPR_CONSTANT
+      && !(strncasecmp (open->access->value.character.string,
+                       "sequential", 10) == 0
+          || strncasecmp (open->access->value.character.string,
+                          "stream", 6) == 0
+          || strncasecmp (open->access->value.character.string,
+                          "append", 6) == 0))
+    {
+      warn_or_error ("POSITION specifier in OPEN statement at %C only allowed "
+                    "for stream or sequential ACCESS");
+    }
+
+#undef warn_or_error
+
   new_st.op = EXEC_OPEN;
   new_st.ext.open = open;
   return MATCH_YES;
@@ -1368,6 +1696,7 @@ gfc_match_close (void)
 {
   gfc_close *close;
   match m;
+  bool warn;
 
   m = gfc_match_char ('(');
   if (m == MATCH_NO)
@@ -1411,6 +1740,19 @@ gfc_match_close (void)
       goto cleanup;
     }
 
+  warn = (close->iostat || close->err) ? true : false;
+
+  /* Checks on the STATUS specifier.  */
+  if (close->status && close->status->expr_type == EXPR_CONSTANT)
+    {
+      static const char * status[] = { "KEEP", "DELETE" };
+
+      if (!compare_to_allowed_values ("STATUS", status, NULL, NULL,
+                                     close->status->value.character.string,
+                                     "CLOSE", warn))
+       goto cleanup;
+    }
+
   new_st.op = EXEC_CLOSE;
   new_st.ext.close = close;
   return MATCH_YES;
index 5ce3b3872118d7cb96a74f047fb371f794c16eb7..67419090c20e30491f9406d4d088f744fce14b4a 100644 (file)
@@ -1,3 +1,18 @@
+2006-10-13  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR fortran/21435
+       * gcc/testsuite/gfortran.dg/io_constraints_3.f90: New test.
+       * gcc/testsuite/gfortran.dg/open_access_append_1.f90: Add checks
+       for compile-time warnings.
+       * gcc/testsuite/gfortran.dg/pr20163-2.f: Likewise.
+       * gcc/testsuite/gfortran.dg/iostat_2.f90: Likewise.
+       * gcc/testsuite/gfortran.dg/label_4.f90: Delete the temporary
+       file.
+       * gcc/testsuite/gfortran.dg/direct_io_2.f90: Add a FILE=
+       specifier.
+       * gcc/testsuite/gfortran.dg/iomsg_1.f90: Add check for
+       compile-time warning.
+
 2006-10-12  Jan Hubicka  <jh@suse.cz>
 
        PR c/28419
 
 2006-10-12 Lee Millward <lee.millward@codesourcery.com>
 
-       PR c++/27961
-       * g++.dg/template/crash60.C: New test.
-       * g++.dg/other/large-size-array.C: Adjust error markers.
-       * g++.dg/parse/crash27.C: Likewise.
-       * g++.dg/template/crash1.C: Likewise.
+       PR c++/27961
+       * g++.dg/template/crash60.C: New test.
+       * g++.dg/other/large-size-array.C: Adjust error markers.
+       * g++.dg/parse/crash27.C: Likewise.
+       * g++.dg/template/crash1.C: Likewise.
        
 2006-10-12  Steve Ellcey  <sje@cup.hp.com>
 
@@ -37,9 +52,9 @@
 
 2006-10-11  Lee Millward  <lee.millward@codesourcery.com>
 
-        PR c++/29024
-        * g++.dg/parse/typedef8.C: New test.
-        * g++.dg/other/mult-stor1.C: Adjust error markers.
+       PR c++/29024
+       * g++.dg/parse/typedef8.C: New test.
+       * g++.dg/other/mult-stor1.C: Adjust error markers.
        
 2006-10-11  Richard Guenther  <rguenther@suse.de>
 
index 13b27b8986ee654cfac672d8c162637c78c80db6..0ebfd7d83517def3b446790657dff8e6a337cb94 100644 (file)
@@ -6,7 +6,7 @@
       PROGRAM FM413
       IMPLICIT LOGICAL (L)
       IMPLICIT CHARACTER*14 (C)
-      OPEN (7, ACCESS = 'DIRECT', RECL = 80, STATUS='REPLACE' )
+      OPEN (7, ACCESS = 'DIRECT', RECL = 80, STATUS='REPLACE', FILE="FOO" )
       IRECN = 13
       IREC = 13
       DO 4132 I = 1,100
diff --git a/gcc/testsuite/gfortran.dg/io_constraints_3.f90 b/gcc/testsuite/gfortran.dg/io_constraints_3.f90
new file mode 100644 (file)
index 0000000..086e488
--- /dev/null
@@ -0,0 +1,191 @@
+! Test some restrictions on the specifiers of OPEN and CLOSE statements.
+! Contributed by Francois-Xavier Coudert (coudert@clipper.ens.fr)
+!
+! { dg-do compile }
+! { dg-options "-ffree-line-length-none -pedantic" }
+  integer,parameter :: mone = -1, zero = 0
+  character(len=*),parameter :: foo = "foo"
+  character(len=20) :: str
+  integer :: u
+
+! Test for warnings, when IOSTAT is used
+
+  open(10, iostat=u,access="sequential   ")
+  open(10, iostat=u,access="sequential   u") ! { dg-warning "ACCESS specifier in OPEN statement" }
+  open(10, iostat=u,access=foo) ! { dg-warning "ACCESS specifier in OPEN statement" }
+  open(10, iostat=u,access="direct")
+  open(10, iostat=u,access="stream")
+  open(10, iostat=u,access="append") ! { dg-warning "Extension: ACCESS specifier in OPEN statement" }
+
+  open(10, iostat=u,action="read")
+  open(10, iostat=u,action="write")
+  open(10, iostat=u,action="readwrite")
+  open(10, iostat=u,action=foo) ! { dg-warning "ACTION specifier in OPEN statement" }
+
+  open(10, iostat=u,blank="ZERO")
+  open(10, iostat=u,blank="nUlL")
+  open(10, iostat=u,blank="NULLL") ! { dg-warning "BLANK specifier in OPEN statement" }
+
+  open(10, iostat=u,delim="apostrophe")
+  open(10, iostat=u,delim="quote")
+  open(10, iostat=u,delim="none")
+  open(10, iostat=u,delim="") ! { dg-warning "DELIM specifier in OPEN statement" }
+
+  open(10, iostat=u,form="formatted")
+  open(10, iostat=u,form="unformatted")
+  open(10, iostat=u,form="default") ! { dg-warning "FORM specifier in OPEN statement" }
+
+  open(10, iostat=u,pad="yes")
+  open(10, iostat=u,pad="no")
+  open(10, iostat=u,pad=foo) ! { dg-warning "PAD specifier in OPEN statement" }
+
+  open(10, iostat=u,position="asis")
+  open(10, iostat=u,position="rewind")
+  open(10, iostat=u,position="append")
+  open(10, iostat=u,position=foo) ! { dg-warning "POSITION specifier in OPEN statement" }
+
+  open(10, iostat=u,recl="ee") ! { dg-warning "must be of type INTEGER" }
+  open(10, iostat=u,recl=0.4) ! { dg-warning "must be of type INTEGER" }
+  open(10, iostat=u,recl=zero) ! { dg-warning "must be positive" }
+  open(10, iostat=u,recl=mone) ! { dg-warning "must be positive" }
+
+  open(10, iostat=u,status="unknown")
+  open(10, iostat=u,status="old")
+  open(10, iostat=u,status=foo) ! { dg-warning "STATUS specifier in OPEN statement" }
+  
+  open(10, iostat=u,status="new") ! { dg-warning "no FILE specifier is present" }
+  open(10, iostat=u,status="replace   ") ! { dg-warning "no FILE specifier is present" }
+  open(10, iostat=u,status="scratch",file=str) ! { dg-warning "cannot have the value SCRATCH if a FILE specifier is present" }
+
+  open(10, iostat=u,form="unformatted",delim="none") ! { dg-warning "not allowed in OPEN statement for unformatted I/O" }
+  open(10, iostat=u,form="unformatted",pad="yes") ! { dg-warning "not allowed in OPEN statement for unformatted I/O" }
+  open(10, iostat=u,form="unformatted",blank="null") ! { dg-warning "not allowed in OPEN statement for unformatted I/O" }
+
+  open(10, iostat=u,access="direct",position="append") ! { dg-warning "only allowed for stream or sequential ACCESS" }
+
+  close(10, iostat=u,status="keep")
+  close(10, iostat=u,status="delete")
+  close(10, iostat=u,status=foo) ! { dg-warning "STATUS specifier in CLOSE statement" }
+
+
+
+! Test for warnings, when an ERR label is specified
+
+  open(10, err=99,access="sequential   ")
+  open(10, err=99,access="sequential   u") ! { dg-warning "ACCESS specifier in OPEN statement" }
+  open(10, err=99,access=foo) ! { dg-warning "ACCESS specifier in OPEN statement" }
+  open(10, err=99,access="direct")
+  open(10, err=99,access="stream")
+  open(10, err=99,access="append") ! { dg-warning "Extension: ACCESS specifier in OPEN statement" }
+
+  open(10, err=99,action="read")
+  open(10, err=99,action="write")
+  open(10, err=99,action="readwrite")
+  open(10, err=99,action=foo) ! { dg-warning "ACTION specifier in OPEN statement" }
+
+  open(10, err=99,blank="ZERO")
+  open(10, err=99,blank="nUlL")
+  open(10, err=99,blank="NULLL") ! { dg-warning "BLANK specifier in OPEN statement" }
+
+  open(10, err=99,delim="apostrophe")
+  open(10, err=99,delim="quote")
+  open(10, err=99,delim="none")
+  open(10, err=99,delim="") ! { dg-warning "DELIM specifier in OPEN statement" }
+
+  open(10, err=99,form="formatted")
+  open(10, err=99,form="unformatted")
+  open(10, err=99,form="default") ! { dg-warning "FORM specifier in OPEN statement" }
+
+  open(10, err=99,pad="yes")
+  open(10, err=99,pad="no")
+  open(10, err=99,pad=foo) ! { dg-warning "PAD specifier in OPEN statement" }
+
+  open(10, err=99,position="asis")
+  open(10, err=99,position="rewind")
+  open(10, err=99,position="append")
+  open(10, err=99,position=foo) ! { dg-warning "POSITION specifier in OPEN statement" }
+
+  open(10, err=99,recl="ee") ! { dg-warning "must be of type INTEGER" }
+  open(10, err=99,recl=0.4) ! { dg-warning "must be of type INTEGER" }
+  open(10, err=99,recl=zero) ! { dg-warning "must be positive" }
+  open(10, err=99,recl=mone) ! { dg-warning "must be positive" }
+
+  open(10, err=99,status="unknown")
+  open(10, err=99,status="old")
+  open(10, err=99,status=foo) ! { dg-warning "STATUS specifier in OPEN statement" }
+  
+  open(10, err=99,status="new") ! { dg-warning "no FILE specifier is present" }
+  open(10, err=99,status="replace   ") ! { dg-warning "no FILE specifier is present" }
+  open(10, err=99,status="scratch",file=str) ! { dg-warning "cannot have the value SCRATCH if a FILE specifier is present" }
+
+  open(10, err=99,form="unformatted",delim="none") ! { dg-warning "not allowed in OPEN statement for unformatted I/O" }
+  open(10, err=99,form="unformatted",pad="yes") ! { dg-warning "not allowed in OPEN statement for unformatted I/O" }
+  open(10, err=99,form="unformatted",blank="null") ! { dg-warning "not allowed in OPEN statement for unformatted I/O" }
+
+  open(10, err=99,access="direct",position="append") ! { dg-warning "only allowed for stream or sequential ACCESS" }
+
+  close(10, err=99,status="keep")
+  close(10, err=99,status="delete")
+  close(10, err=99,status=foo) ! { dg-warning "STATUS specifier in CLOSE statement" }
+
+ 99 continue
+
+! Test for errors
+
+  open(10,access="sequential   ")
+  open(10,access="sequential   u") ! { dg-error "ACCESS specifier in OPEN statement" }
+  open(10,access=foo) ! { dg-error "ACCESS specifier in OPEN statement" }
+  open(10,access="direct")
+  open(10,access="stream")
+  open(10,access="append") ! { dg-warning "Extension: ACCESS specifier in OPEN statement" }
+
+  open(10,action="read")
+  open(10,action="write")
+  open(10,action="readwrite")
+  open(10,action=foo) ! { dg-error "ACTION specifier in OPEN statement" }
+
+  open(10,blank="ZERO")
+  open(10,blank="nUlL")
+  open(10,blank="NULLL") ! { dg-error "BLANK specifier in OPEN statement" }
+
+  open(10,delim="apostrophe")
+  open(10,delim="quote")
+  open(10,delim="none")
+  open(10,delim="") ! { dg-error "DELIM specifier in OPEN statement" }
+
+  open(10,form="formatted")
+  open(10,form="unformatted")
+  open(10,form="default") ! { dg-error "FORM specifier in OPEN statement" }
+
+  open(10,pad="yes")
+  open(10,pad="no")
+  open(10,pad=foo) ! { dg-error "PAD specifier in OPEN statement" }
+
+  open(10,position="asis")
+  open(10,position="rewind")
+  open(10,position="append")
+  open(10,position=foo) ! { dg-error "POSITION specifier in OPEN statement" }
+
+  open(10,recl="ee") ! { dg-error "must be of type INTEGER" }
+  open(10,recl=0.4) ! { dg-error "must be of type INTEGER" }
+  open(10,recl=zero) ! { dg-error "must be positive" }
+  open(10,recl=mone) ! { dg-error "must be positive" }
+
+  open(10,status="unknown")
+  open(10,status="old")
+  open(10,status=foo) ! { dg-error "STATUS specifier in OPEN statement" }
+  
+  open(10,status="new") ! { dg-error "no FILE specifier is present" }
+  open(10,status="replace   ") ! { dg-error "no FILE specifier is present" }
+  open(10,status="scratch",file=str) ! { dg-error "cannot have the value SCRATCH if a FILE specifier is present" }
+
+  open(10,form="unformatted",delim="none") ! { dg-error "not allowed in OPEN statement for unformatted I/O" }
+  open(10,form="unformatted",pad="yes") ! { dg-error "not allowed in OPEN statement for unformatted I/O" }
+  open(10,form="unformatted",blank="null") ! { dg-error "not allowed in OPEN statement for unformatted I/O" }
+
+  open(10,access="direct",position="append") ! { dg-error "only allowed for stream or sequential ACCESS" }
+
+  close(10,status="keep")
+  close(10,status="delete")
+  close(10,status=foo) ! { dg-error "STATUS specifier in CLOSE statement" }
+end
index 20c8e8b89620cf5a2e99b2cd69f517f125b97977..0916fd861f11a3f5c5bd530ad1a0e5e7d5bb9a49 100644 (file)
@@ -22,7 +22,7 @@ program iomsg_test
   if (ch .ne. 'Bad unit number in OPEN statement') call abort
 
   ! Test iomsg with close
-  close(23,status="no_idea", err=500, iomsg=ch)
+  close(23,status="no_idea", err=500, iomsg=ch) ! { dg-warning "STATUS specifier in CLOSE statement.*has invalid value" }
 500 continue
   if (ch .ne. "Bad STATUS parameter in CLOSE statement") call abort
 end program iomsg_test
index 124567c1e3221b4a18f7fd18db9f6c6818c3626c..afda93e8092d7e8560a5223b810b4db5ee69d257 100644 (file)
@@ -1,7 +1,7 @@
 ! PR libfortran/23784
 ! { dg-do run }
   integer i
-  close(10, status="whatever", iostat=i)
+  close(10, status="whatever", iostat=i) ! { dg-warning "STATUS specifier in CLOSE statement.*has invalid value" }
   if (i == 0) call abort()
   write(17,*) 'foo'
   close(17, status="delete")
index 68b2291fbeac5fe1c2b8f4a96e6603ff8a1d20b9..ade0f167f81faaea9f40c1c64e35585d2e85cb92 100644 (file)
@@ -5,4 +5,5 @@
   open(unit=12,err=99)
 99 print *,"could not open file ..."
 98 continue ! { dg-warning "Label 98 .* defined but not used" }
+  close(unit=12,status="delete")
 end
index 7aa7991a75ac05636a9a57c5a9fe7a95efe4d03b..8dae327968df72509d287db733d1bf45d2b38763 100644 (file)
@@ -3,10 +3,10 @@
   open (10,file="foo")
   close (10,status="delete")
 
-  open (10,file="foo",access="append") ! { dg-output ".*Extension.*" }
+  open (10,file="foo",access="append") ! { dg-warning "Extension: ACCESS specifier in OPEN statement" }
   write (10,*) 42
   close (10,status="keep")
-  open (10,file="foo",access="append") ! { dg-output ".*Extension.*" }
+  open (10,file="foo",access="append") ! { dg-warning "Extension: ACCESS specifier in OPEN statement" }
   write (10,*) -42
   close (10,status="keep")
 
@@ -18,3 +18,4 @@
   close (10,status="delete")
 
   end
+! { dg-output ".*Extension.*Extension" } 
index c0b2573ed93a314a2797f2f7f7ec3d3679cf988d..0638aeaf9ddbe35b24436bc31565185a81323056 100644 (file)
@@ -1,4 +1,4 @@
-       open(10,status="foo",err=100)
+       open(10,status="foo",err=100) ! { dg-warning "STATUS specifier in OPEN statement .* has invalid value" }
        call abort
   100  continue
        open(10,status="scratch")