(j3.2006) Is there something wrong with this?

Van Snyder Van.Snyder
Thu Oct 29 19:25:53 EDT 2015


I think the following module ought to be OK:

module M

  type, abstract :: T1
  end type T1

  type, extends(t1) :: T2
  end type T2

contains

  class(t1) function F1 ( ) result ( R1 )
    allocatable :: R1
    allocate ( t2 :: r1 )
    select type ( r1 )
    type is ( t2 )
      r1 = t2()
    end select
  end function F1

  function F2 ( ) result ( R2 )
    class(t1), allocatable :: R2
    allocate ( t2 :: r2 )
    r2 = t2()
  end function F2

end module M

None of the processors I have will compile it.  They complain in F1 that
the type of R1 is not T2, and that R1 is not polymorphic in the SELECT
TYPE statement.  One of them complains about the assignment "r2 = t2()"
in F2.

Is it defective?

I believe the SELECT TYPE construct ought not to be needed.  Indeed, I
believe the ALLOCATE is also not needed, but it illustrates a problem
that all my processors complain about in F1 (but which does not occur in
F2).

12.6.2.2p3 says the type and type parameters of the result of the
function may be specified by a type specification in the FUNCTION
statement.  It is silent concerning whether the result is or is not
polymorphic.  Is R1 polymorphic?  I believe so.





More information about the J3 mailing list