Possible problem with ASSOCIATED and procedure pointer

marco restelli mrestelli@gmail.com
Fri Aug 14 09:40:00 GMT 2015


Hi all,
   the attached code is rejected by gfortran (version 6.0.0 20150813
(experimental)). My impression is that the code is fine, but there
might also be fine points related to derived type pointer components
and procedure pointers which make the code invalid.

ifort also rejects the code, although with a different error, while
nag accepts it.



$ gfortran test.f90 -o test
test.f90:24:36:

    p_to_f_ex = associated( pp%p_f , f_example ) ! error
                                    1
Error: »target« argument of »associated« intrinsic at (1) must be the
same type and kind as »pointer«



module m
 implicit none

 type :: t_pp
  procedure(i_f), pointer, nopass :: p_f => null()
 end type t_pp

 abstract interface
  pure function i_f(x) result(i)
   implicit none
   real, intent(in) :: x
   integer :: i
  end function i_f
 end interface

contains

 subroutine s(pp)
  class(t_pp), intent(in) :: pp

  logical :: p_to_f_ex
  procedure(i_f), pointer :: p_f

   p_to_f_ex = associated( pp%p_f , f_example ) ! error
   write(*,*) p_to_f_ex

   p_f => pp%p_f
   p_to_f_ex = associated( p_f , f_example ) ! works
   write(*,*) p_to_f_ex

 end subroutine s

 pure function f_example(x) result(i)
  real, intent(in) :: x
  integer :: i
   i = floor(x)
 end function f_example

end module m


program p
 use m
 implicit none
 type(t_pp) :: a
  a%p_f => f_example
  call s(a)
end program p



More information about the Fortran mailing list