pointersfortranprocedurefortran2003nag-fortran

Procedure pointer returned from a function with nagfor


I try to use procedure pointers as a return of a function in Fortran. The following minimal code works with gfortran (tested with 4.8.1) but not with nagfor (NAG 6.0):

function foo() result(f_p)
  implicit none
  procedure(), pointer :: f_p
  f_p => null()
end function foo

nagfor complains with:

Error: test.f90, line 5: Multiply defined symbol F_P
   detected at ::@F_P
Error: test.f90, line 5: F_P is not a procedure name
   detected at F_P@<end-of-statement>
Warning: test.f90, line 7: Result F_P of function FOO has not been assigned a value
[NAG Fortran Compiler pass 1 error termination, 2 errors, 1 warning]

Why is this?

Note: I'm very well aware of the danger for memory leaks when using procedure pointers in this way.


Solution

  • I work on the NAG Fortran Compiler and I can confirm that it does not yet implement this Fortran 2003 feature (functions returning procedure pointers). Support for the feature is tentatively scheduled for the next (6.1) release.