This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[fortran, patch] PR25094 - check for private types in public interfaces


As is, gfortran accepts PRIVATE procedures in PUBLIC interfaces which expect 
dummy arguments of PRIVATE type. The patch is straightforward, the testcase 
the reporter's.


:ADDPATCH fortran:

gcc/fortran:
2007-07-02  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/25094
	* resolve.c (resolve_fl_procedure): Added check for PRIVATE types 
	in PUBLIC interfaces.

gcc/testsuite:
2007-07-02  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/25094
	* gfortran.dg/interface_13.f90: New test.


Regression tested on i686-pc-linux-gnu. Ok for trunk?

Regards
	Daniel
Index: fortran/resolve.c
===================================================================
--- fortran/resolve.c	(revision 126214)
+++ fortran/resolve.c	(working copy)
@@ -6591,6 +6603,8 @@
 	&& sym->ns->parent->proc_name->attr.flavor == FL_MODULE)
       && gfc_check_access(sym->attr.access, sym->ns->default_access))
     {
+      gfc_interface *iface;
+
       for (arg = sym->formal; arg; arg = arg->next)
 	{
 	  if (arg->sym
@@ -6608,6 +6622,29 @@
 	      return FAILURE;
 	    }
 	}
+
+      /* PUBLIC interfaces may expose PRIVATE procedures that take takes
+	 PRIVAT to the containing module.  */
+      for (iface = sym->generic; iface; iface = iface->next)
+	{
+	  for (arg = iface->sym->formal; arg; arg = arg->next)
+	    {
+	      if (arg->sym
+		  && arg->sym->ts.type == BT_DERIVED
+		  && !arg->sym->ts.derived->attr.use_assoc
+		  && !gfc_check_access (arg->sym->ts.derived->attr.access,
+					arg->sym->ts.derived->ns->default_access))
+		{
+		  gfc_error_now ("Procedure '%s' in PUBLIC interface '%s' at %L takes "
+				 "dummy arguments of '%s' which is PRIVATE",
+				 iface->sym->name, sym->name, &iface->sym->declared_at,
+				gfc_typename(&arg->sym->ts));
+		  /* Stop this message from recurring.  */
+		  arg->sym->ts.derived->attr.access = ACCESS_PUBLIC;
+		  return FAILURE;
+		}
+	     }
+	}
     }
 
   /* An external symbol may not have an initializer because it is taken to be
Index: testsuite/gfortran.dg/interface_13.f90
===================================================================
--- testsuite/gfortran.dg/interface_13.f90	(revision 0)
+++ testsuite/gfortran.dg/interface_13.f90	(revision 0)
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options "-c" }
+! Testcase from PR fortran/25094
+! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
+
+MODULE M1
+  TYPE T1
+    INTEGER :: I
+  END TYPE T1
+  INTERFACE I
+    MODULE PROCEDURE F1        ! { dg-error "PUBLIC interface" }
+  END INTERFACE
+  PRIVATE ! :: T1,F1
+  PUBLIC  :: I
+CONTAINS
+  INTEGER FUNCTION F1(D)
+    TYPE(T1) :: D
+    F1 = D%I
+  END FUNCTION
+END MODULE
+
+! { dg-final { cleanup-modules "M1" } }

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