This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, fortran] PR20903 - types shouldn't propagate into interfaces
- From: Paul Thomas <paulthomas2 at wanadoo dot fr>
- To: fortran at gcc dot gnu dot org, patch <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 11 Jul 2006 16:17:18 +0200
- Subject: [Patch, fortran] PR20903 - types shouldn't propagate into interfaces
:ADDPATCH fortran:
To quote the standard:
"An interface body specifies all of the procedure's characteristics and
these
shall be consistent with those specified in the procedure definition, except
that the interface may specify a procedure that is not pure if the procedure
is defined to be pure(12.3.2)."
At present, gfortran violates this by allowing derived types to be
declared outside of the scope of the interface body. The patch does not
need any further description. The testcase checks both the error and
that nothing is broken; specifically, it checks that internally declared
and use associated derived types are accepted.
Regtested on FC5/Athlon. OK for trunk and 4.1?
Paul
2006-07-11 Paul Thomas <pault@gcc.gnu.org>
PR fortran/20903
* decl.c (variable_decl): Add error if a derived type is not
from the current namespace if the namespace is an interface
body.
2006-07-11 Paul Thomas <pault@gcc.gnu.org>
PR fortran/20903
* gfortran.dg/interface_derived_type_1.f90: New test.
Index: gcc/fortran/decl.c
===================================================================
*** gcc/fortran/decl.c (revision 115317)
--- gcc/fortran/decl.c (working copy)
*************** variable_decl (int elem)
*** 1176,1181 ****
--- 1176,1195 ----
goto cleanup;
}
+ /* An interface body specifies all of the procedure?s characteristics and these
+ shall be consistent with those specified in the procedure definition, except
+ that the interface may specify a procedure that is not pure if the procedure
+ is defined to be pure(12.3.2). */
+ if (current_ts.type == BT_DERIVED
+ && gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY
+ && current_ts.derived->ns != gfc_current_ns)
+ {
+ gfc_error ("the type of '%s' at %C has not been declared within the "
+ "interface", name, &sym->declared_at);
+ m = MATCH_ERROR;
+ goto cleanup;
+ }
+
/* In functions that have a RESULT variable defined, the function
name always refers to function calls. Therefore, the name is
not allowed to appear in specification statements. */
! { dg-do compile }
! Test the fix for PR20903, in which derived types could be host associated within
! interface bodies.
!
! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
!
module test
implicit none
type fcnparms
integer :: i
end type fcnparms
contains
subroutine sim_1(func1,params)
interface
function func1(fparams)
type(fcnparms) :: fparams ! { dg-error "not been declared within the interface" }
real :: func1
end function func1
end interface
type(fcnparms) :: params
end subroutine sim_1
subroutine sim_2(func2,params)
interface
function func2(fparams) ! This is OK because of the derived type decl.
type fcnparms
integer :: i
end type fcnparms
type(fcnparms) :: fparams
real :: func2
end function func2
end interface
type(fcnparms) :: params ! This is OK, of course
end subroutine sim_2
end module test
module type_decl
implicit none
type fcnparms
integer :: i
end type fcnparms
end module type_decl
subroutine sim_3(func3,params)
use type_decl
interface
function func3(fparams)
use type_decl
type(fcnparms) :: fparams ! This is OK - use associated
real :: func3
end function func3
end interface
type(fcnparms) :: params ! -ditto-
end subroutine sim_3
2006-07-11 Paul Thomas <pault@gcc.gnu.org>
PR fortran/20903
* decl.c (variable_decl): Add error if a derived type is not
from the current namespace if the namespace is an interface
body.
2006-07-11 Paul Thomas <pault@gcc.gnu.org>
PR fortran/20903
* gfortran.dg/interface_derived_type_1.f90: New test.