This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, Fortran] Change error into std-notify (F2003) for private type to public interfaces
- 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: Wed, 12 Sep 2007 18:35:47 +0200
- Subject: [Patch, Fortran] Change error into std-notify (F2003) for private type to public interfaces
:ADDPATCH fortran:
Fortran 95 has the restriction:
"5.2.3 Accessibility statements
[...]
Constraint: A module procedure that has a dummy argument or function
result of a type that has PRIVATE accessibility shall have PRIVATE
accessibility and shall not have a generic identifier that has PUBLIC
accessibility."
In Fortran 2003 this restriction is gone.
Build and regtested on x86-64/Linux. Ok for the trunk?
Tobias
2007-09-12 Tobias Burnus <burnus@net-b.de>
* resolve.c (resolve_fl_procedure): Allow private dummies
for Fortran 2003.
2007-09-12 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/interface_15.f90: Compile with -std=f95.
* gfortran.dg/private_type_1.f90: Ditto
* gfortran.dg/interface_18.f90: New.
* gfortran.dg/private_type_8.f90: New.
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (Revision 128440)
+++ gcc/fortran/resolve.c (Arbeitskopie)
@@ -6888,12 +6888,13 @@ resolve_fl_procedure (gfc_symbol *sym, i
&& 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))
+ arg->sym->ts.derived->ns->default_access)
+ && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: '%s' is of a "
+ "PRIVATE type and cannot be a dummy argument"
+ " of '%s', which is PUBLIC at %L",
+ arg->sym->name, sym->name, &sym->declared_at)
+ == FAILURE)
{
- gfc_error_now ("'%s' is of a PRIVATE type and cannot be "
- "a dummy argument of '%s', which is "
- "PUBLIC at %L", arg->sym->name, sym->name,
- &sym->declared_at);
/* Stop this message from recurring. */
arg->sym->ts.derived->attr.access = ACCESS_PUBLIC;
return FAILURE;
@@ -6910,12 +6911,14 @@ resolve_fl_procedure (gfc_symbol *sym, i
&& 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))
+ arg->sym->ts.derived->ns->default_access)
+ && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: 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)) == FAILURE)
{
- 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;
@@ -6933,12 +6936,14 @@ resolve_fl_procedure (gfc_symbol *sym, i
&& 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))
+ arg->sym->ts.derived->ns->default_access)
+ && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: 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)) == FAILURE)
{
- 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;
Index: gcc/testsuite/gfortran.dg/interface_15.f90
===================================================================
--- gcc/testsuite/gfortran.dg/interface_15.f90 (Revision 128440)
+++ gcc/testsuite/gfortran.dg/interface_15.f90 (Arbeitskopie)
@@ -1,5 +1,5 @@
! { dg-do compile }
-! { dg-options "-c" }
+! { dg-options "-c -std=f95" }
! Testcase from PR fortran/25094
! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
Index: gcc/testsuite/gfortran.dg/interface_18.f90
===================================================================
--- gcc/testsuite/gfortran.dg/interface_18.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/interface_18.f90 (Revision 0)
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+!
+! Public procedures with private types for the dummies
+! is valid F2003, but invalid per Fortran 95, Sect. 5.2.3
+! See interface_15.f90 for the F95 test case.
+!
+ module mytype_application
+ implicit none
+ private
+ public :: mytype_test
+ type :: mytype_type
+ integer :: i=0
+ end type mytype_type
+ contains
+ subroutine mytype_test( mytype )
+ type(mytype_type), intent(in out) :: mytype
+ end subroutine mytype_test
+ end module mytype_application
+
+! { dg-final { cleanup-modules "mytype_application" } }
Index: gcc/testsuite/gfortran.dg/private_type_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/private_type_1.f90 (Revision 128440)
+++ gcc/testsuite/gfortran.dg/private_type_1.f90 (Arbeitskopie)
@@ -1,4 +1,5 @@
! { dg-do compile }
+! { dg-options "-std=f95" }
! PR21986 - test based on original example.
! A public subroutine must not have private-type, dummy arguments.
! Contributed by Paul Thomas <pault@gcc.gnu.org>
Index: gcc/testsuite/gfortran.dg/private_type_8.f90
===================================================================
--- gcc/testsuite/gfortran.dg/private_type_8.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/private_type_8.f90 (Revision 0)
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! A public subroutine can have private-type, dummy arguments
+! in Fortran 2003 (but not in Fortran 95).
+! See private_type_1.f90 for the F95 test.
+!
+module modboom
+ implicit none
+ private
+ public:: dummysub
+ type:: intwrapper
+ integer n
+ end type intwrapper
+contains
+ subroutine dummysub(size, arg_array)
+ type(intwrapper) :: size
+ real, dimension(size%n) :: arg_array
+ real :: local_array(4)
+ end subroutine dummysub
+end module modboom
+
+! { dg-final { cleanup-modules "modboom" } }