Move_alloc with polymorphic arguments loses dynamic type

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

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)


  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


Hi NeilC,

This one was reported to us on April 3rd, 2018 and was logged as TPR#25499.

We do have an engineer investigating the issue and hope to have a fix available soon.

Best Regards,