Consider the following code:
module m implicit none abstract interface function I_f() result( j ) integer :: j end function I_f end interface type :: t procedure(I_f), nopass, pointer :: m_f => null() contains procedure, pass(this) :: f => get_f end type t contains function get_f( this ) result( f_ptr ) class(t), intent(in) :: this procedure(I_f), pointer :: f_ptr f_ptr => this%m_f return end function get_f end module m
program p use m, only : t, I_f implicit none procedure(I_f), pointer :: f_ptr type(t) :: foo f_ptr => foo%f() stop end program p
Compiler 17 processes the module code without any complaints, but gives an unexpected error with the main program:
1>Compiling with Intel(R) Visual Fortran Compiler 22.214.171.124 [IA-32]... 1>m.f90 1>p.f90 1>p.f90(10): error #8191: The procedure target must be a procedure or a procedure pointer. 1>ifort: error #10298: problem during post processing of parallel object compilation
Steve Lionel (Intel) wrote:
We don't fully support functions that return procedure pointers - it's one of the missing F2008 items listed here. This error is a fallout from that.
Thanks for your post.
May I please request someone from the Intel Fortran team to recheck: I feel the link you provide above has some information that appears incorrect. Looking at the standard documents, my read is "functions that return procedure pointers" is a Fortran 2003 feature, not Fortran 2008. Note John Reid wrote back in 2004, "A function may have a procedure pointer result"
Looking at the Fortran 2008 standard document, the enhancement is "pointer function reference can denote a variable in any variable definition context" toward the item in the above link that has "Pointer functions on left side of assignment statement" such as f(i) = 5 where f is pointer to a function that accepts the type of i as argument. But since the code in the original post is not doing so, can one not expect a Fortran 2003 compiler to support it?
The above link states, "As of compiler version 16.0 (Intel Parallel Studio XE 2016), the Intel® [Visual] Fortran compiler is fully compliant with the ISO/IEC 1539-1:2004 Fortran language standard (Fortran 2003 Language)," which is what raised my expectation with the code in the original post Or if the feature is not supported, shouldn't it catch it at the source, meaning compilation of module m itself should flag an error?
Very interesting. We had this tagged in our list as a F08 feature and we had not finished it yet. But you're right, it's actually a F03 feature. Curiously, your version of the function itself compiles ok but others give a "not yet implemented" message.
I have converted the "feature request" to a defect report, issue ID is DPD200517332. Thanks for the nudge.
Thanks a bunch, Steve. Here's a variation that unfortunately results in an ICE, if you don't mind passing that along to development:
module m implicit none abstract interface function I_f() result( j ) integer :: j end function I_f end interface procedure(I_f), pointer :: f contains function get_f() result( f_ptr ) procedure(I_f), pointer :: f_ptr f_ptr => f return end function get_f end module m
program p use m, only : I_f, get_f implicit none procedure(I_f), pointer :: f_ptr f_ptr => get_f stop end program p
Compiling with Intel(R) Visual Fortran Compiler 126.96.36.199 [IA-32]... p.f90 fortcom: Fatal: There has been an internal compiler error (C0000005). ifort: error #10298: problem during post processing of parallel object compilation compilation aborted for p.f90 (code 1)