I actually only fill this to ensure my test case does not get lost.

Fortran 2003 contains ("12.4 Procedure reference"):

"C1229 (R1221) A procedure-name shall be the name of an external procedure, a
dummy procedure, a module procedure, a procedure pointer, or a specific
intrinsic function that is listed in 13.6 and not marked with a bullet(*).

NOTE 12.16 -- This standard does not allow internal procedures to be used as
actual arguments, in part to simplify the problem of ensuring that internal
procedures with recursive hosts access entities from the correct instance
(12.5.2.3) of the host."

In Fortran 2008 (draft 07-007r3) this restriction is gone:

"C1235 (R1223) A procedure-name shall be the name of an external, internal,
module, or dummy procedure, a specific intrinsic function listed in 13.6 and
not marked with a bullet (*), or a procedure pointer."


Test program (initially created for PR 34133):

! { dg-do run }
! PR fortran/34133
!
! Test of using internal bind(C) procedures as
! actual argument. Bind(c) on internal procedures and
! internal procedures are actual argument are
! Fortran 2008 (draft) extension.
!
module test_mod
  use iso_c_binding
  implicit none
contains
  subroutine test_sub(a, arg, res)
    interface
      subroutine a(x) bind(C)
        import
        integer(c_int), intent(inout) :: x
      end subroutine a
    end interface
    integer(c_int), intent(inout) :: arg
    integer(c_int), intent(in) :: res
    call a(arg)
    if(arg /= res) call abort()
  end subroutine test_sub
  subroutine test_func(a, arg, res)
    interface
      integer(c_int) function a(x) bind(C)
        import
        integer(c_int), intent(in) :: x
      end function a
    end interface
    integer(c_int), intent(in) :: arg
    integer(c_int), intent(in) :: res
    if(a(arg) /= res) call abort()
  end subroutine test_func
end module test_mod

program main
  use test_mod
  implicit none
  call test_sub (one, 33, 7*33)
  call test_func(two, 23, -123*23)
contains
  subroutine one(x) bind(c)
     integer(c_int),intent(inout) :: x
     x = 7*x
  end subroutine one
  integer(c_int) function two(y) bind(c)
     integer(c_int),intent(in) :: y
     two = -123*y
  end function two
end program main
! { dg-final { cleanup-modules "test_mod" } }


-- 
           Summary: F2008: Allow internal procedures as actual argument
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34162

Reply via email to