<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Expression result ignored for procedure argument in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593967#M172006</link>
    <description>&lt;P&gt;the latest ifx nightly build also gives the error you describe.&amp;nbsp; I will have to check the syntax to see if this code is conformant.&amp;nbsp; It is suspicious when something crashes the NAG compiler.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Apr 2024 20:20:32 GMT</pubDate>
    <dc:creator>Ron_Green</dc:creator>
    <dc:date>2024-04-30T20:20:32Z</dc:date>
    <item>
      <title>Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593943#M172004</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;The following code&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;module mod1
    implicit none

    abstract interface
        subroutine i_proc()
        end subroutine
    end interface

contains
    function gen_proc(str) result(p)
        procedure(i_proc), pointer :: p
        character(*), intent(in) :: str

        p =&amp;gt; cp
    contains
        subroutine cp()
            print*,'str=',trim(str)
        end subroutine
    end function

    subroutine match(p)
        procedure(i_proc) :: p
        call p()
    end subroutine
end module mod1

use mod1

implicit none

call match(gen_proc('Hello'))

end&lt;/LI-CODE&gt;&lt;P&gt;Fails to compile with&lt;/P&gt;&lt;LI-CODE lang="bash"&gt;$ ifx -V return-proc.f90 
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.1.0 Build 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

 Intel(R) Fortran 24.0-1472.3
return-proc.f90(31): error #6636: When a dummy argument is a subroutine, the corresponding actual argument must also be a subroutine.
call match(gen_proc('Hello'))
-----------^
compilation aborted for return-proc.f90 (code 1)&lt;/LI-CODE&gt;&lt;P&gt;I'm not sure if my interpretation is correct, but it seems like the expression's result is not being considered, and the compiler is assuming that I'm trying to pass a function as actual argument.&lt;/P&gt;&lt;P&gt;When compiling the code with gfortran 13, I get the expected outcome:&lt;/P&gt;&lt;LI-CODE lang="bash"&gt;$ gfortran -std=f2018 return-proc.f90 &amp;amp;&amp;amp; ./a.out 
/usr/bin/ld: warning: /tmp/cc2N2xku.o: requires executable stack (because the .note.GNU-stack section is executable)
 str=Hello&lt;/LI-CODE&gt;&lt;P&gt;(The warning issued by the linker is just a side-effect of &lt;A href="https://en.wikipedia.org/wiki/Nested_function#No-execute_stacks" target="_self"&gt;the way GCC implements nested functions&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 17:54:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593943#M172004</guid>
      <dc:creator>jwmwalrus</dc:creator>
      <dc:date>2024-04-30T17:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593964#M172005</link>
      <description>&lt;P&gt;nagfor gets an internal compiler error&lt;/P&gt;
&lt;LI-CODE lang="none"&gt;nagfor -v return-proc.f90 
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7125
return-proc.f90:
Segmentation violation
Internal error - please report this bug&lt;/LI-CODE&gt;
&lt;P&gt;I'll try our ifx mainline branch.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:17:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593964#M172005</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2024-04-30T20:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593967#M172006</link>
      <description>&lt;P&gt;the latest ifx nightly build also gives the error you describe.&amp;nbsp; I will have to check the syntax to see if this code is conformant.&amp;nbsp; It is suspicious when something crashes the NAG compiler.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:20:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593967#M172006</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2024-04-30T20:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593968#M172007</link>
      <description>&lt;P&gt;Even if it did compile and run. I don't think it should work and is probably not legal code. I used a temporary pointer to hold the result of gen_proc, than passed that to match. This compiles and runs but crashes.&lt;/P&gt;&lt;P&gt;After the execution returns from gen_proc, its argument str is removed from the stack and is gone. Then when you call the pointer to it's internal procedure cp, it attempts to access str and protection violates.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:25:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593968#M172007</guid>
      <dc:creator>Andrew_Smith</dc:creator>
      <dc:date>2024-04-30T20:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593970#M172008</link>
      <description>&lt;P&gt;This page from IBM Fortran says its not legal to call an internal procedure from outside.&amp;nbsp;&lt;A href="https://www.ibm.com/docs/en/xffbg/121.141?topic=procedures-procedure-pointers-fortran-2003" target="_blank"&gt;Procedure pointers (Fortran 2003) - IBM Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:40:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593970#M172008</guid>
      <dc:creator>Andrew_Smith</dc:creator>
      <dc:date>2024-04-30T20:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593973#M172009</link>
      <description>&lt;P&gt;The code is simply implementing a closure.&lt;/P&gt;&lt;P&gt;From what I understood&amp;nbsp; in &lt;A href="https://stevelionel.com/drfortran/2009/09/02/doctor-fortran-in-think-thank-thunk/" target="_self"&gt;this old post from Steve Lionel&lt;/A&gt;, the context from gen_proc execution should be kept around (which is probably what GCC refers to when performing the stack jump).&lt;/P&gt;&lt;P&gt;In Steve Lionel's example, the contained procedure is passed as an argument to another procedure directly, but imho same (context preservation) rules should apply here... unless procedure pointers to contained procedures are not allowed at all as function results in Fortran.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 21:07:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593973#M172009</guid>
      <dc:creator>jwmwalrus</dc:creator>
      <dc:date>2024-04-30T21:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593976#M172010</link>
      <description>&lt;P&gt;Oh. Interesting.&lt;/P&gt;&lt;P&gt;Thanks for the pointer.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 21:15:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593976#M172010</guid>
      <dc:creator>jwmwalrus</dc:creator>
      <dc:date>2024-04-30T21:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593985#M172012</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.intel.com/t5/user/viewprofilepage/user-id/85280"&gt;@Andrew_Smith&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;This page from IBM Fortran says its not legal to call an internal procedure from outside.&amp;nbsp;&lt;A href="https://www.ibm.com/docs/en/xffbg/121.141?topic=procedures-procedure-pointers-fortran-2003" target="_blank" rel="noopener"&gt;Procedure pointers (Fortran 2003) - IBM Documentation&lt;/A&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Starting Fortran 2008 revision (current standard is 2023) around 14 years ago, this restriction around internal procedures has been lifted in a way.&lt;/P&gt;&lt;P&gt;Meaning, starting with 2008 standard publication, "An internal procedure can be used as an actual argument&lt;BR /&gt;or procedure pointer target."&amp;nbsp; This effectively provides a mechanism for the internal procedure to be invoked in a scope that is external to the host.&lt;/P&gt;&lt;P&gt;The standard can be referred to for further details; the book "Modern Fortran Explained" provides some commentary about this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 22:31:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593985#M172012</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2024-04-30T22:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593995#M172014</link>
      <description>&lt;P&gt;The copy of nagfor I have (7.2-7203) doesn't display an ICE, but it doesn't generate an object much less an exe.&amp;nbsp; However, I agree with Andrew that this is not legal code. The "thunk" created by the pointer assignment p=&amp;gt;cp becomes undefined on return from gen_proc.&amp;nbsp; Whether it "works" or not is unpredictable.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 23:25:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1593995#M172014</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2024-04-30T23:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1594006#M172015</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.intel.com/t5/user/viewprofilepage/user-id/5442"&gt;@Steve_Lionel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;The copy of nagfor I have (7.2-7203) doesn't display an ICE, but it doesn't generate an object much less an exe.&amp;nbsp; However, I agree with Andrew that this is not legal code. The "thunk" created by the pointer assignment p=&amp;gt;cp becomes undefined on return from gen_proc.&amp;nbsp; Whether it "works" or not is unpredictable.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;In (a draft of) the Fortran 2023 standard, around the &lt;EM&gt;function-stmt&lt;/EM&gt; definition, I see the following&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;If the function result is a pointer,&amp;nbsp;on return the pointer association status of the function result shall not be undefined.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;And there's also the following note:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;The function result is similar to any other entity (variable or &lt;STRONG&gt;procedure pointer&lt;/STRONG&gt;) local to a function subprogram.&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;Its existence begins when execution of the function is initiated and ends when execution of the function is&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;terminated. However, because the final value of this entity is used subsequently in the evaluation of the&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;expression that invoked the function, an implementation might defer releasing the storage occupied by that&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;entity until after its value has been used in expression evaluation.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Which seems to be exactly what gfortran is doing (i.e., using the result in the immediate expression).&lt;/P&gt;&lt;P&gt;But if you say the code is not legal, then I believe you.&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 00:14:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1594006#M172015</guid>
      <dc:creator>jwmwalrus</dc:creator>
      <dc:date>2024-05-01T00:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1594204#M172017</link>
      <description>&lt;P&gt;&lt;a href="https://community.intel.com/t5/user/viewprofilepage/user-id/296168"&gt;@jwmwalrus&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;For whatever it's worth, my understanding is your code in the original post does not conform per the standard (c.f. proxy document 23-007r1.pdf).&amp;nbsp; But it is not so per the stated reasons in this thread, whether with a thunk (no such thing is recognized by the standard) or an internal subprogram or any such argument.&amp;nbsp; Rather the non-conformance is simply due to a reference to any undefined object ('str`) on line 17 on the code in your original post.&lt;/P&gt;&lt;P&gt;Consider a slight variant of your code in the original post where the object reference is replaced with something valid, two options - a) a module entity thus with default SAVE attribute or a "static" (per common CS parlance) object `SAVE` in the host.&amp;nbsp; I reckon such code conforms starting with Fortran 2008 standard revision.&amp;nbsp; And any processor (compiler) unable to complete the instructions with such a program shall be non-conforming with Fortran 2008 and subsequent revisions (2018 and 2023(:&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;module m
   abstract interface
      subroutine Iproc()
      end subroutine
   end interface
   character(len=:), allocatable, save :: s !&amp;lt;-- option a ; comment out for option b
contains
   function gen_proc(str) result(p)
      procedure(Iproc), pointer :: p
      character(*), intent(in) :: str
      !character(len=:), allocatable, save :: s !&amp;lt;-- uncomment this line for option b
      s = str
      p =&amp;gt; cp
   contains
      subroutine cp()
         print*,'str=',trim(s)
      end subroutine
   end function
   subroutine match( p )
      procedure(Iproc) :: p
      call p()
   end subroutine
end module
   use m
   call match( gen_proc('Hello') )
end&lt;/LI-CODE&gt;&lt;P&gt;Intel Support team may want to submit above case&amp;nbsp;with Intel Fortran team as a bug incident for resolution.&lt;/P&gt;&lt;P&gt;In the meantime, a further variant of above works with Intel Fortran processor and that's good news.&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;module m
   abstract interface
      subroutine Iproc()
      end subroutine
   end interface
   character(len=:), allocatable, save :: s !&amp;lt;-- option a ; comment out for option b
contains
   function gen_proc(str) result(p)
      procedure(Iproc), pointer :: p
      character(*), intent(in) :: str
      !character(len=:), allocatable, save :: s !&amp;lt;-- uncomment this line for option b
      s = str
      p =&amp;gt; cp
   contains
      subroutine cp()
         print*,'str=',trim(s)
      end subroutine
   end function
   subroutine match( p )
      procedure(Iproc) :: p
      call p()
   end subroutine
end module
   use m
   procedure(Iproc), pointer :: proc
   proc =&amp;gt; gen_proc('Hello')
   call match( proc )
end&lt;/LI-CODE&gt;&lt;LI-CODE lang="none"&gt;C:\temp&amp;gt;ifx /standard-semantics /free p.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.1.0 Build 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.36.32537.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:p.exe
-subsystem:console
p.obj

C:\temp&amp;gt;p.exe
 str=Hello&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 May 2024 17:01:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1594204#M172017</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2024-05-01T17:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Expression result ignored for procedure argument</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1594206#M172018</link>
      <description>&lt;P&gt;"An internal procedure cannot be invoked using a procedure pointer from either Fortran or C after the host&lt;BR /&gt;instance completes execution, because the pointer is then undefined. While the host instance is active, however,&lt;BR /&gt;if an internal procedure was passed as an actual argument or is the target of a procedure pointer, it could be&lt;BR /&gt;invoked from outside of the host subprogram." (F2023 15.5.1)&lt;/P&gt;&lt;P&gt;Malcolm Cohen (NAG) agrees the code is invalid and is fixing nagfor to give a run-time error in this case.&lt;/P&gt;&lt;P&gt;The text you cite refers to the function return value (procedure pointer in this case) itself, not the pointer's target. For example, a function returning an allocatable array keeps the result around until consumed.&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2024 17:07:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Expression-result-ignored-for-procedure-argument/m-p/1594206#M172018</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2024-05-01T17:07:17Z</dc:date>
    </item>
  </channel>
</rss>

