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

Bill Long longb
Fri Oct 30 16:03:33 EDT 2015


Cray?s compiler compiles the code, but with a advisory warning that there is a code path in F1 for which the result variable is not defined.  The compiler is not (yet) clever enough to realize that the ALLOCATE statement effectively eliminates the SELECT TYPE test.  There is no issue with the CLASS declaration on the FUNCTION statement in F1. 

Cheers,
Bill



On Oct 29, 2015, at 6:25 PM, Van Snyder <van.snyder at jpl.nasa.gov> wrote:

> 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.
> 
> 
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3

Bill Long                                                                       longb at cray.com
Fortran Technical Support  &                                  voice:  651-605-9024
Bioinformatics Software Development                     fax:  651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101





More information about the J3 mailing list