https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78009
Bug ID: 78009
Summary: [OOP] polymorphic component of derived type array
slice handling error
Product: gcc
Version: 6.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: daanvanvugt at gmail dot com
Target Milestone: ---
When setting a component of a polymorphic type in an array memory offsets of
the base type are used. This only occurs if it is nested in another allocatable
array.
See the attached program for an example. Expected output is
1 0
1 0
... etc
instead a different memory region is set to 1.
program test
type :: t
integer :: a
end type t
type, extends(t) :: tt
integer :: b
end type tt
type :: group
class(t), allocatable, dimension(:) :: unit
end type group
type(group), allocatable, dimension(:) :: groups
allocate(groups(1))
allocate(tt::groups(1)%unit(10))
groups(1)%unit(:)%a = 1
select type (units => groups(1)%unit)
type is (tt)
do i=1,10
write(*,*) units(i)%a, units(i)%b
end do
end select
end program test