This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, Fortran] PR38065 Fix checking of contained function
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>, "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>
- Date: Tue, 11 Nov 2008 16:09:44 +0100
- Subject: [Patch, Fortran] PR38065 Fix checking of contained function
gfortran had two bugs:
a) A function, contained in a public module procedure, which returns a
private derived type, was rejected claiming that the function is public,
which is nonsense
b) A public module function, returning a private derived type was
rejected with -std=f2003, but they are only invalid in -std=f95.
The patch fixes both problems and should be save for the regression only
phase as it is simple and prints an error less often than before, which
makes it safe.
Build and regtested on x86-64-linux.
OK for the trunk?
Tobias
2008-11-11 Tobias Burnus <burnus@net-b.de>
PR fortran/38065
* resolve.c (resolve_fntype): Fix private derived type checking.
2008-11-11 Tobias Burnus <burnus@net-b.de>
PR fortran/38065
* gfortran.dg/private_type_11.f90: New test.
* gfortran.dg/private_type_12.f90: New test.
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (Revision 141763)
+++ gcc/fortran/resolve.c (Arbeitskopie)
@@ -10179,12 +10179,14 @@ resolve_fntype (gfc_namespace *ns)
}
if (sym->ts.type == BT_DERIVED && !sym->ts.derived->attr.use_assoc
+ && !sym->attr.contained
&& !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);
+ gfc_notify_std (GFC_STD_F2003, "Fortran 2003: PUBLIC function '%s' at "
+ "%L of PRIVATE type '%s'", sym->name,
+ &sym->declared_at, sym->ts.derived->name);
}
if (ns->entries)
Index: gcc/testsuite/gfortran.dg/private_type_11.f90
===================================================================
--- gcc/testsuite/gfortran.dg/private_type_11.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/private_type_11.f90 (Revision 0)
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+! PR fortran/38065
+!
+! Reported by Norman S. Clerman
+! and reduced by Joost VandeVondele
+!
+MODULE M1
+ IMPLICIT NONE
+ PRIVATE
+ TYPE T1
+ INTEGER :: I1
+ END TYPE T1
+ PUBLIC :: S1,F2
+CONTAINS
+ SUBROUTINE S1
+ CONTAINS
+ TYPE(T1) FUNCTION F1()
+ END FUNCTION F1
+ END SUBROUTINE S1
+ TYPE(T1) FUNCTION F2()
+ END FUNCTION F2
+END MODULE M1
Index: gcc/testsuite/gfortran.dg/private_type_12.f90
===================================================================
--- gcc/testsuite/gfortran.dg/private_type_12.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/private_type_12.f90 (Revision 0)
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-std=f95" }
+! PR fortran/38065
+!
+! Reported by Norman S. Clerman
+! and reduced by Joost VandeVondele
+!
+MODULE M1
+ IMPLICIT NONE
+ PRIVATE
+ TYPE T1
+ INTEGER :: I1
+ END TYPE T1
+ PUBLIC :: S1,F2
+CONTAINS
+ SUBROUTINE S1
+ CONTAINS
+ TYPE(T1) FUNCTION F1()
+ END FUNCTION F1
+ END SUBROUTINE S1
+ TYPE(T1) FUNCTION F2() ! { dg-error "Fortran 2003: PUBLIC variable 'f2'" }
+ END FUNCTION F2
+END MODULE M1