https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119802
Bug ID: 119802
Summary: Defined assignment not called for component of derived
type
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: abensonca at gcc dot gnu.org
Target Milestone: ---
A type-bound assignment of an allocatable component of a derived type is not
called if the parent type does not use type-bound assignment:
module bugMod
type :: rm
integer :: c
contains
procedure :: rma
generic :: assignment(=) => rma
end type rm
type :: w
type(rm), allocatable :: wc ! "allocatable" attribute required for this
bug
contains
! uncomment the following two lines - using defined assignment avoids this
bug
! procedure :: wa
! generic :: assignment(=) => wa
end type w
contains
subroutine rma(to,from)
implicit none
class(rm), intent( out) :: to
class(rm), intent(in ) :: from
to%c=from%c+1
return
end subroutine rma
subroutine wa(to,from)
implicit none
class(w), intent( out) :: to
class(w), intent(in ) :: from
allocate(to%wc)
to%wc=from%wc
return
end subroutine wa
end module bugMod
program bug
use bugMod
implicit none
type(w) :: i
i=w(rm(3))
write (0,*) "expected 4, got ",i%wc%c
end program bug
$ gfortran bug.F90
$ ./a.out
expected 4, got 3
With ifort I get:
expected 4, got 4