[J3] Question on Table 10.8: Intrinsic assignment type conformance

Steve Lionel steve at stevelionel.com
Thu Jun 13 18:55:43 EDT 2019


On 6/13/2019 5:44 PM, Vipul Parekh via J3 wrote:
> Does the following code conform, particularly 'b= f()' assignment shown below?
>
> module b_m
>     type :: b_t
>        integer :: i = 0
>     end type
> end module
> module e_m
>     use b_m, only : b_t
>     type, extends(b_t) :: e_t
>     end type
> contains
>     function f() result(r)
>        class(b_t), allocatable :: r
>        allocate( e_t :: r)
>     end function
> end module
> program p
>     use b_m, only : b_t
>     use e_m, only : f
>     type(b_t) :: b
>     b = f()
> end program
>
> Two compilers I tried process the code ok, but I have doubt given the
> "same derived type as the variable" listed in Table 10.8 for the "type
> of expr" in a "variable = expr" assignment.
>
10.2.1.2p1(4) Intrinsic assignment statement says:

"if the variable is polymorphic it shall be type compatible with expr; 
otherwise the declared types of the variable and expr shall conform as 
specified in Table 10.8"

Note the use of "declared type". The declared type of b and f() are both 
b_t, so this conforms.

As for the warning from the Cray compiler, it is correct. An ALLOCATE of 
a variable without SOURCE= does not define the variable. See 19.6.5.

Steve



More information about the J3 mailing list