Issue with a procedure defined with a generic name returning procedure pointer

Samuel Debionne samuel.debionne@ujf-grenoble.fr
Mon Apr 15 13:32:00 GMT 2013


Hello,
I'm having an issue with a procedure defined with a generic name
returning a procedure pointer. In short :

    ptr => specific_name_get_proc_ptr()	! OK
    ptr => generic_name_get_proc_ptr()  ! KO
           1
Error: Interface mismatch in procedure pointer assignment at (1):
Type/rank mismatch in return value of 'generic_name_get_proc_ptr'

Since the same construct works with other compilers, I'm wondering if it
is a gfortran bug or if I'm doing something non-standard. Attached is a
test case that show the problem with gfortran 4.7.2.
Regards,
Samuel
-------------- next part --------------
! Declare an interface
module iface

  abstract interface
      function foo(arg1) result(res)
          real, intent(in) :: arg1
          double precision :: res
      end function foo
  end interface

end module iface
    
! Implement the interface
module impl
  
contains

  function impl_foo(arg1) result(res)
    real, intent(in) :: arg1
    double precision :: res
      
    res = dble(arg1)
      
  end function impl_foo

end module impl


module test
    use :: iface

    interface generic_name_get_proc_ptr
        module procedure specific_name_get_proc_ptr
    end interface

contains
        
    function specific_name_get_proc_ptr() result(res)
        use :: impl

        procedure(foo), pointer :: res

        res => impl_foo

    end function specific_name_get_proc_ptr

end module test

program crash_test
    use :: test

    procedure(foo), pointer :: ptr
    
    ptr => specific_name_get_proc_ptr()   ! OK
    ptr => generic_name_get_proc_ptr()    ! KO

end program crash_test


More information about the Fortran mailing list