https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106948

            Bug ID: 106948
           Summary: pure subroutine with pure procedure as dummy
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jfeng33 at hotmail dot com
  Target Milestone: ---

Compiling the below code failed and gave the following error in which f was
declared to be pure:

   22 |     x = int(f(real(x)) * 0.1)
      |             1
Error: Reference to impure function ‘f’ at (1) within a PURE procedure



module a
  implicit none

  interface new
    pure module subroutine b(x, f)
      integer, intent(inout) :: x
      interface
        pure function f(x) result(r)
          real, intent(in) :: x
          real :: r
        end function f
      end interface
    end subroutine b
  end interface new
end module a

submodule(a) a_b
  implicit none

contains
  module procedure b
    x = int(f(real(x)) * 0.1)
  end procedure b
end submodule a_b


program test
  use a
  implicit none

  integer :: x

  x = 10
  call new(x, g)
  print *, x

contains

  pure function g(y) result(r)
    real, intent(in) :: y
    real :: r

    r = sqrt(y)
  end function g
end program test

Reply via email to