https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
Bug ID: 98573
Summary: Dynamic type lost on assignment
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: davidhneill at gmail dot com
Target Milestone: ---
Created attachment 49904
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49904&action=edit
Minimal reproducer
In the following example, the dynamic type of an unlimited polymorphic array is
lost on an assignment but conserved (as expected) on a sourced allocation.
This happens in all versions I've tried: 7.5.0, 8.4.0, 9.3.0, 10.2.0
My system is Ubuntu 20.04 on Intel hardware with all gfortran versions
installed directly from the Ubuntu repositories.
$ cat type_lost.f90
module foo
type, public:: box
class(*), allocatable :: val(:)
end type
contains
subroutine store1(this, val)
class(box), intent(out) :: this
class(*), intent(in) :: val(:)
this%val = val
end subroutine store1
subroutine store2(this, val)
class(box), intent(out) :: this
class(*), intent(in) :: val(:)
allocate(this%val, source=val)
end subroutine store2
subroutine vector_type(val)
class(*), intent(in) :: val(:)
select type (val)
type is (integer)
print '("INTEGER")'
class default
print '("OTHER")'
end select
end subroutine vector_type
end module foo
program prog
use foo
type(box) :: b
call store1(b, [1, 2, 3])
call vector_type(b%val) ! OTHER
call store2(b, [1, 2, 3])
call vector_type(b%val) ! INTEGER
end program
$ gfortran -g -Wall -Wextra minimal.f90
$ ./a.out
OTHER
INTEGER