I have a program that associates a pointer to an instance of a derived type, then checks whether the pointer is associated with the intended object. When I compile this with gfortran (9.2.0), the associated() function returns true as expected. However, when I compile the same program with ifort (19.0.4.243), the associated() function returns false.
Here is the program in question:
module mod_pointer_association
type mytype
end type mytype
contains
subroutine test_association(obj)
class(mytype), target, intent(in)::obj
class(mytype), pointer::ptr
ptr=>obj
if (.not. associated(ptr)) then
print *, "ptr not associated"
error stop
end if
if (.not. associated(ptr, obj)) then
print *, "ptr not associated with obj"
error stop
end if
end subroutine test_association
end module mod_pointer_association
program test_pointer_assocation
use mod_pointer_association
type(mytype), target::myobj
call test_association(myobj)
end program test_pointer_assocation
gfortran produces no output, as expected. ifort produces the following output:
$ ./test_pointer_association
ptr not associated with obj