I don't know if this a bug or a feature or what but it's pretty sneaky and a really dangerous one.
real(8), dimension(2):: x
call subroutine sub1(x,x)
end program test_program
[On another module]
subroutine sub1(argIN, argOUT)
real(8), dimension(2), intent(in):: argIN
real(8), dimension(2), intent(out):: argOUT
argOUT(2)=argIN(1)+argIN(2) !The exact same as the previous line, only assigned to argOUT(2)
end subroutine test_sub
This program, you'd expect to print:
1.0000 1.0000 !For the old x
2.0000 2.0000 !For the x after the call of the subroutine
But instead, it prints:
Also, if you put a "print*, argOUT" command in the subroutine just between the declarations and the rest of the body it will even print "1.0000 1.0000", even though the argOUT hasn't been assigned any value yet.
So basically, if you do it that way (use the same variable for both of the arguments) the IN and the OUT arguments inside the subroutine are implicitly linked (argIN=argOUT) for no apparent reason.
The solution is of course easy. You either use different variables in the call statement or you use an intermediate variable in the subroutine as a buffer for the in argument (e.g temp=argIN(1) and then use temp). But unless, you know this quirkiness then you won't even think to implement the solution.
Is this intended? Is this a bug? Why dosen't the compiler at least show a warning?
Compiler: Intel(R) Visual Fortran Compiler 188.8.131.52