Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resourcespage or contact an Altera Authorized Distributor.

CLASS question

OP1
New Contributor III
512 Views

The code below does not compile with XE 17 (probably justly so). It compiles if U and V are not declared as allocatable arrays.The help for CLASS in the provided documentation does not seem to cover this case, maybe I am missing something here?

PROGRAM P
IMPLICIT NONE
TYPE,ABSTRACT :: T
END TYPE T
TYPE,EXTENDS(T) :: T1
END TYPE T1
TYPE(T1),ALLOCATABLE :: U(:)
CALL S(U)
CONTAINS
SUBROUTINE S(V)
IMPLICIT NONE
CLASS(T),ALLOCATABLE :: V(:)
END SUBROUTINE S
END PROGRAM P

 

0 Kudos
2 Replies
IanH
Honored Contributor III
512 Views

This isn't permitted.  Inside `S`, you could (re-)allocate the `V` dummy argument to be some other extension of `T`, that was incompatible with the declared type of the actual argument `U`.  To avoid this there is a requirement that the declared type and polymorphic/non-polymorphic nature of the actual and dummy arguments must match if the dummy has the pointer or allocatable attribute (F2008 12.5.2.5p2).

I found a hint of an incomplete mention of this in the ifort documentation for allocatable arrays under "Array arguments", but it applies to scalar dummy arguments and pointer dummy arguments too.

0 Kudos
OP1
New Contributor III
512 Views

Ah, I understand now. Thanks for the clear explanation!
 

0 Kudos
Reply