[J3] [EXTERNAL] Can a type-bound procedure be passed as an actual argument

Clune, Thomas L. (GSFC-6101) thomas.l.clune at nasa.gov
Wed Jan 11 18:58:48 UTC 2023


This is not permitted.  (But would be nice!)


R1524 actual-arg is expr

24 or variable

25 or procedure-name

26 or proc-component-ref

27 or conditional-arg

28 or alt-return-spec

29

t1%foo is a binding name which is not in that list.

Real_foo can of course be passed, but it is not directly accessible through t1.


  *   Tom

From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Wednesday, January 11, 2023 at 1:08 PM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Daniel C Chen <cdchen at ca.ibm.com>
Subject: [EXTERNAL] [J3] Can a type-bound procedure be passed as an actual argument

Hi All,
Consider the following code
Case 1:
  type dt
   contains
    procedure, nopass :: foo => real_foo
  end type
  interface
    subroutine real_foo()
    end
  end interface
  type(dt) :: t1
  call sub1(t1%foo)    !!! Is it legal to pass t1%foo as actual argument?
end
Case 2:
module m
  type dt
   contains
    procedure :: foo => real_foo
  end type
contains
    subroutine real_foo(this)
      class(dt) :: this
    end
end

program main
use m
  type(dt) :: t1
  call sub1(t1%foo)   !!! Is it legal to pass t1%foo as actual argument?

end

I couldn’t find any wording in the standard (F2018) that prohibits the two usages above, and yet a couple of compilers that I have access to flags error message.

Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20230111/8e357602/attachment.htm>


More information about the J3 mailing list