[gfortran, patch] PR 25093: PUBLIC function of PRIVATE type

Erik Edelmann erik.edelmann@iki.fi
Sun Jan 8 01:45:00 GMT 2006


:ADDPATCH fortran:

Here's a little patch to fix PR 25093; PUBLIC functions were
allowed to be of PRIVATE type. This patch inserts a check for
this in resolve.c (resolve_fntype).

Reg.tested on Linux/x86, on mainline and 4.1.  Ok to commit?


        Erik


2005-01-08  Erik Edelmann  <eedelman@gcc.gnu.org>

        PR fortran/25093
        * resolve.c (resolve_fntype): Check that PUBLIC functions
         aren't of PRIVATE type.


2005-01-08  Erik Edelmann  <eedelman@gcc.gnu.org>

        PR fortran/25093
        * gfortran.dg/private_type_4.f90: New.
-------------- next part --------------
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 109451)
+++ gcc/fortran/resolve.c	(working copy)
@@ -5626,6 +5626,15 @@ resolve_fntype (gfc_namespace * ns)
       sym->attr.untyped = 1;
     }
 
+  if (sym->ts.type == BT_DERIVED && !sym->ts.derived->attr.use_assoc
+      && !gfc_check_access (sym->ts.derived->attr.access,
+                            sym->ts.derived->ns->default_access)
+      && gfc_check_access (sym->attr.access, sym->ns->default_access))
+    {
+      gfc_error ("PUBLIC function '%s' at %L cannot be of PRIVATE type '%s'",
+                 sym->name, &sym->declared_at, sym->ts.derived->name);
+    }
+
   if (ns->entries)
     for (el = ns->entries->next; el; el = el->next)
       {
-------------- next part --------------
! { dg-do compile }
! PR 25093: Check that a PUBLIC function can't be of PRIVATE type
module m1

    type :: t1
        integer :: i
    end type t1

    private :: t1
    public :: f1     ! { dg-error "cannot be of PRIVATE type" }

contains

    type(t1) function f1()
    end function

end module


More information about the Gcc-patches mailing list