I’d like to report a bug with the 18.4 compiler. The polymorphic destination variable of the move_alloc call in following example loses the dynamic type of the polymorphic source variable. [I previously reported this for 18.1 to the HPC consultants at LANL, but don’t know whether it was ever conveyed to PGI.]
$ pgfortran --version
pgfortran 18.4-0 64-bit target on x86-64 Linux -tp nehalem$ pgfortran bug.f90
$ ./a.out
wrong type after move_alloc
2
type, abstract :: json_value
end type
type, extends(json_value) :: json_integer
integer :: value
end type
type :: json_builder
class(json_value), allocatable :: result
end type
class(json_value), allocatable :: val
call sub(val)
contains
subroutine sub(value)
class(json_value), allocatable, intent(out) :: value
type(json_builder) :: builder
allocate(builder%result, source=json_integer(42))
select type (result => builder%result)
type is (json_integer)
class default
stop 1
end select
call move_alloc(builder%result, value)
select type (value)
type is (json_integer)
class default
print *, 'wrong type after move_alloc'
stop 2
end select
end subroutine
end