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

Polymorphic pointer size

WileyOne
Novice
1,157 Views

Compiler: ifx (IFX) 2025.0.4

OS: Rocky Linux 8.9 (Green Obsidian)

 

I believe the pointer `px` should have size 0 the third time `method` is called, but it has size 5. Its array size is not being reset between calls, even though it becomes disassociated.

 

 

 

module myMod
implicit none

type, abstract :: base
end type

type, extends(base) :: extension
end type

contains
subroutine method(bool)
    logical, intent(in) :: bool
    class(base), allocatable, target :: x(:)
    type(extension), pointer :: px(:) => null()

    if (bool) allocate(extension :: x(5))

    select type(dummy => x)
        type is(extension)
            px => dummy
            print *, 'type'
        class default
            px => null()
            print *, 'default'
    end select

    print *, size(px), associated(px)
end subroutine
end module

program main
use myMod
implicit none

call method(.false.)
call method(.true.)
call method(.false.)

end program

 

 

 

Labels (1)
0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
1,079 Views

Calling size on a disassociated pointer is not permitted - the results are unpredictable.

"ARRAY shall be assumed-rank or an array. It shall not be an unallocated allocatable variable or a pointer that is not associated. "

View solution in original post

2 Replies
Steve_Lionel
Honored Contributor III
1,080 Views

Calling size on a disassociated pointer is not permitted - the results are unpredictable.

"ARRAY shall be assumed-rank or an array. It shall not be an unallocated allocatable variable or a pointer that is not associated. "

WileyOne
Novice
1,017 Views

I missed that when checking the standard. Thank you!

0 Kudos
Reply