Reported by Bob Corbett of SUN to the J3 mailing list (who was initially not fully convinced that the code is valid). The following program is regarded as valid but it fails with sunf95 and gfortran (4.3/4.4/4.5, no IMPORT exists in 4.2) to compile. (It works with NAG f95, ifort, g95, xlf90.) gfortran's error message is: TYPE(T3) X 1 Error: the type of 'x' at (1) has not been declared within the interface "The problem, of course, is the definition of the derived type T2 following the interface block. Section 12.3.2.1 of the Fortran 2003 standard says regarding the IMPORT statement If an entity that is made accessible by this means is accessed by host association and is defined in the host scoping unit, it shall be explicitly declared prior to the interface body. That clearly requires T1 and T3 to be defined prior to the interface body, but it does not require T2 to be defined prior to the interface body. Therefore, the program appears to be standard conforming." MODULE MOD TYPE T1 SEQUENCE TYPE(T2), POINTER :: P END TYPE TYPE T2 SEQUENCE INTEGER I END TYPE END PROGRAM MAIN USE MOD, T3 => T1, T4 => T2 TYPE T1 SEQUENCE TYPE(T2), POINTER :: P END TYPE INTERFACE SUBR SUBROUTINE SUBR1(X) IMPORT T3 TYPE(T3) X END SUBROUTINE SUBROUTINE SUBR2(X) IMPORT T1 TYPE(T1) X END SUBROUTINE END INTERFACE TYPE T2 SEQUENCE REAL X END TYPE END SUBROUTINE SUBR1(X) USE MOD TYPE(T1) X END SUBROUTINE SUBR2(X) TYPE T1 SEQUENCE TYPE(T2), POINTER :: P END TYPE TYPE T2 SEQUENCE REAL X END TYPE TYPE(T1) X END
Confirmed. Here is a reduced test case, which does not have the problem with T2 discussed in comment #0, but still fails with the same error message: MODULE MOD TYPE T1 TYPE(T1), POINTER :: P END TYPE END PROGRAM MAIN USE MOD, T3 => T1 INTERFACE SUBR SUBROUTINE SUBR1(X) IMPORT T3 TYPE(T3) X END SUBROUTINE END INTERFACE END The error only appears if the imported type is renamed in the USE statement.
Mine. The fix is completely trivial: Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (Revision 146676) +++ gcc/fortran/decl.c (Arbeitskopie) @@ -2741,7 +2741,7 @@ goto next_item; } - st = gfc_new_symtree (&gfc_current_ns->sym_root, name); + st = gfc_new_symtree (&gfc_current_ns->sym_root, sym->name); st->n.sym = sym; sym->refs++; sym->attr.imported = 1;
Subject: Bug 39688 Author: janus Date: Sat Apr 25 08:11:48 2009 New Revision: 146762 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146762 Log: 2009-04-25 Janus Weil <janus@gcc.gnu.org> PR fortran/39688 * decl.c (gfc_match_import): Use 'sym->name' instead of 'name'. They differ if the symbol has been use-renamed. 2009-04-25 Janus Weil <janus@gcc.gnu.org> PR fortran/39688 * gfortran.dg/import7.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/import7.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/decl.c trunk/gcc/testsuite/ChangeLog
Fixed in r146762. Closing.