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]

[gfortran] Don't allow IMPLICIT after IMPLICIT NONE


A small random fix for an issue I spotted while looking at something else.  We
didn't verify that no further IMPLICIT (NONE) statements come after an
IMPLICIT NONE statement.  I pondered doing some magic with the statement order
checks in parse.c but decided to take this simpler approach.

Bubblestrapped and regtested.  I will add the attached testcase to the
testsuite.  Ok?

- Tobi

2005-04-29  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	* gfortran.h (gfc_namespace): Add seen_implicit_none field.
	* symbol.c (gfc_set_implicit_none): Give error if there's a previous
	IMPLICIT NONE, set seen_implicit_none.
	(gfc_merge_new_implicit): Error if there's an IMPLICIT NONE statement.

	
Index: gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.66
diff -u -p -r1.66 gfortran.h
--- gfortran.h	28 Apr 2005 21:09:03 -0000	1.66
+++ gfortran.h	28 Apr 2005 23:26:21 -0000
@@ -817,7 +817,7 @@ typedef struct gfc_namespace
 
   gfc_charlen *cl_list;
 
-  int save_all, seen_save;
+  int save_all, seen_save, seen_implicit_none;
 
   /* Normally we don't need to refcount namespaces.  However when we read
      a module containing a function with multiple entry points, this
Index: symbol.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/symbol.c,v
retrieving revision 1.28
diff -u -p -r1.28 symbol.c
--- symbol.c	28 Apr 2005 21:09:04 -0000	1.28
+++ symbol.c	28 Apr 2005 23:26:22 -0000
@@ -106,6 +106,14 @@ gfc_set_implicit_none (void)
 {
   int i;
 
+  if (gfc_current_ns->seen_implicit_none)
+    {
+      gfc_error ("Duplicate IMPLICIT NONE statement at %C");
+      return;
+    }
+
+  gfc_current_ns->seen_implicit_none = 1;
+
   for (i = 0; i < GFC_LETTERS; i++)
     {
       gfc_clear_ts (&gfc_current_ns->default_type[i]);
@@ -160,6 +168,12 @@ gfc_merge_new_implicit (gfc_typespec * t
 {
   int i;
 
+  if (gfc_current_ns->seen_implicit_none)
+    {
+      gfc_error ("Cannot specify IMPLICIT at %C after IMPLICIT NONE");
+      return FAILURE;
+    }
+
   for (i = 0; i < GFC_LETTERS; i++)
     {
       if (new_flag[i])
! { dg-do compile }
! Verify error diagnosis for invalid combinations of IMPLICIT statements
IMPLICIT NONE
IMPLICIT NONE ! { dg-error "Duplicate" }
END

SUBROUTINE a
IMPLICIT REAL(b-j) ! { dg-error "cannot follow" }
implicit none      ! { dg-error "cannot follow" }
END SUBROUTINE a

subroutine b
implicit none
implicit real(g-k) ! { dg-error "Cannot specify" }
end subroutine b

subroutine c
implicit real(a-b)
implicit integer (b-c) ! { dg-error "already" }
implicit real(d-f), complex(f-g) ! { dg-error "already" }
end subroutine c

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