[J3] Polymorphic dummy arrays

Steidel, Jon L jon.l.steidel at intel.com
Mon Jan 7 17:07:26 EST 2019


Happy New Year,

I have a user that wants to be pointed to words in the standard that I cannot find.  I would appreciate any help anyone can offer.

Subroutine func has  a dummy argument  that is an array of polymorphic class T.  It is called with an actual argument array of type S, which extends type T.  The user wants to have the dummy array be explicit shape.  But passing a simple address to func is insufficient as the dummy argument is polymorphic; the subroutine needs to at least know the size of each element as well as a base address.

program class_type_conv

implicit none

type :: t
integer :: i = 1
end type

type, extends(t) :: s
real :: r = 1.0
end type

type(s), dimension(1:2) :: x

call func(x)
print *,x(1)%i, x(1)%r
print *,x(2)%i, x(2)%r

contains

subroutine func(x)
!  class(t), dimension(1:2), intent(out) :: x   ! original test
class(t), dimension(:), intent(out) :: x           ! modified test

call inc(x)
end subroutine

subroutine inc(x)
type(t), dimension(1:2), intent(out) :: x
x(:)%i = x(:)%i + 1
end subroutine

end

One compiler I have access to diagnoses the declaration of the explicit shape dummy array in func (the commented out line) stating a polymorphic dummy array must be allocatable, pointer, or assumed shape. Passing a descriptor here solves the problem as there is element size or inter-element spacing information in the descriptor.

I can a restriction that says a polymorphic object must have the POINTER or ALLOCATABLE attribute or be a dummy argument (C708).  I can also find a requirement that a procedure with a polymorphic dummy argument requires an explicit interface (15.4.2.2.)  But I cannot find a requirement that a dummy array of polymorphic objects must be assumed shape.  Can someone point me to those words?

Note that if the dummy polymorphic array is required to be assume shape, then passing this dummy array from as an actual argument func to the dummy argument x of inc is not legal.  15.5.2.4 Ordinary dummy variables, p2 sentence 3 states "If the actual argument is a polymorphic assumed-size array, the dummy argument shall be polymorphic."  In subroutine inc, x is not polymorphic.


Thanks,

-jon



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20190107/500b785e/attachment.html>


More information about the J3 mailing list