public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/106948] New: pure subroutine with pure procedure as dummy
@ 2022-09-15  1:44 jfeng33 at hotmail dot com
  2022-09-15 18:44 ` [Bug fortran/106948] " anlauf at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: jfeng33 at hotmail dot com @ 2022-09-15  1:44 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug fortran/106948] pure subroutine with pure procedure as dummy
  2022-09-15  1:44 [Bug fortran/106948] New: pure subroutine with pure procedure as dummy jfeng33 at hotmail dot com
@ 2022-09-15 18:44 ` anlauf at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-09-15 18:44 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-09-15
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed.

Likely a problem due to use of submodules.  A simplified, but otherwise
equivalent version, such as below, works:

module a
  implicit none

  interface new
     module procedure :: b
  end interface new

contains
  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
    x = int(f(real(x)) * 0.1)
  end subroutine b
end module a

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-15 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15  1:44 [Bug fortran/106948] New: pure subroutine with pure procedure as dummy jfeng33 at hotmail dot com
2022-09-15 18:44 ` [Bug fortran/106948] " anlauf at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).