In some cases an internal procedure will use a module procedure instead of another internal procedure (in the same host unit) with the same name. In the example below, R(x) calls f(x), but it uses the module's f(x) instead of the one internal to g(x) (as probably intended). module test_functions contains subroutine f(x) implicit none real, intent(inout) :: x x = 2 * x end subroutine f subroutine g(x) implicit none real, intent(inout) :: x call R(x) contains subroutine R(x) implicit none real, intent(inout) :: x call f(x) end subroutine R subroutine f(x) implicit none real, intent(inout) :: x x = 3 * x end subroutine f end subroutine g end module program scope use test_functions real :: x = 3.0, y = 3.0 call f(x) call g(y) write(*, *) x, y end program Compiling and running with gfortran 5.4, 7.4, 8.1, gives: 6.00000000 6.00000000 Compiling and running with ifort 18.0 gives: 6.000000 9.000000 This does not happen if f(x) is a function instead of a subroutine, or if the call to f(x) is made directly in g(x) rather than in R(x).
Confirmed from at least 4.8 up to trunk (10.0).
The issue depends on the order of the internal procedures R and f of g. Placing f in front of R leads to correct results.