Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

PACK () and CLASS entities

Harald1
New Contributor II
203 Views

Hello,

the following example shows that PACK() of CLASS entities may lose the dynamic type:

program p
  implicit none
  type t
     integer :: i
  end type t
  type, extends(t) :: t2
     real :: x = 3.
  end type t2
  class(t), allocatable :: x(:), y(:)
  allocate (t2 :: x(3))
  x% i = [1,2,3]
  print *, x% i
! y    = x                    ! OK
  print *, "Testing merge:"
  y    = merge (x, x, .true.) ! OK
  print *, y% i
  call check ()
  print *, "Testing pack:"
  y    = pack (x, .true.)     ! not OK
  print *, y% i
  call check ()
contains
  subroutine check ()
    print *, "same_type_as (x,y) =", same_type_as (x,y)
    select type (x)
    type is (t2)
       print *, "x is t2"
    class default
       print *, "x is not OK"
    end select
    select type (y)
    type is (t2)
       print *, "y is t2 (OK)"
    class default
       print *, "y is not OK"
    end select
  end subroutine check
end

NAG produces the expected result:

 1 2 3
 Testing merge:
 1 2 3
 same_type_as (x,y) = T
 x is t2
 y is t2 (OK)
 Testing pack:
 1 2 3
 same_type_as (x,y) = T
 x is t2
 y is t2 (OK)

 Intel 24.0-1693.2 howver gives:

           1           2           3
 Testing merge:
           1           2           3
 same_type_as (x,y) = T
 x is t2
 y is t2 (OK)
 Testing pack:
           1           2           3
 same_type_as (x,y) = F
 x is t2
 y is not OK

 So while MERGE() has been fixed in the meantime, intrinsic PACK() was obviously missed.

Thanks,

Harald

 

0 Kudos
1 Reply
TobiasK
Moderator
81 Views

Hello @Harald1


thanks for reporting this, I created a JIRA for the developers. CMPLRLLVM-59922


Best


0 Kudos
Reply