(j3.2006) question about IMPORT and derived types

Robert Corbett Robert.Corbett
Tue Apr 7 22:13:59 EDT 2009


The following program fails to compile with every compiler I used
to compile it including Sun's:

       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

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.  Have I missed something?

Bob Corbett



More information about the J3 mailing list