- Notifications
You must be signed in to change notification settings - Fork 15.3k
Labels
Description
Consider the following code:
module m type base integer :: i contains procedure :: bassgn generic :: assignment(=) => bassgn end type type, extends(base) :: child integer :: j end type type container class(base), allocatable :: b1 end type contains impure elemental subroutine bassgn( a, b ) class(base), intent(out) :: a class(base), intent(in) :: b print*, "in bassgn" a%i = b%i + 1 select type ( a ) type is ( child ) print*, "a is child" select type ( b ) type is ( child ) print*, "b is child" a%j = b%j + 1 end select end select end subroutine end module program genericAssignmentDtIntrinAssgn027 use m type(container) :: c1, c2, c3 pointer :: c2 allocatable :: c3 allocate ( c2, c3 ) allocate ( c2%b1, source = child(1,2) ) c3 = c2 end program Expected output:
> a.out in bassgn a is child b is child Flang produces:
in bassgn The standard says the following about the intrinsic assignment of c3 = c2 [24-007: 10.2.1.3, paragraph 15, page 178]:
For a noncoarray allocatable component the following sequence of operations is applied. (1) If the component of the variable is allocated, it is deallocated. (2) If the component of the value of expr is allocated, the corresponding component of the variable is allocated with the same dynamic type and type parameters as the component of the value of expr. If it is an array, it is allocated with the same bounds. The value of the component of the value of expr is then assigned to the corresponding component of the variable using defined assignment if the declared type of the component has a type-bound defined assignment consistent with the component, and intrinsic assignment for the dynamic type of that component otherwise. So c3%b1 should be allocated with the dynamic type of child first before calling the defined assignment bassgn. Then both select type constructs inside the subroutine should be executed.