Open
Description
This Tweet alerted me to something in Fortran that I was not aware of:
https://twitter.com/fortrantip/status/1479071485859962880
If an argument is passed to a subroutine/function that is a variable wrapped in parentheses, then a copy of the value is taken before applying pass-by-reference:
module m
implicit none
contains
subroutine double(i, i2)
integer :: i
integer :: i2
intent(in) :: i
intent(out) :: i2
print *, "incoming double, i = ", i
i2 = 2*i
print *, "outgoing double, i = ", i
end subroutine double
end module m
program copy
use m
implicit none
integer :: j, z
j=3
call double(j, j)
print *, "(1b) in main, j = ", j
call double((j), j)
print *, "(2) in main, j = ", j
end program copy
We have a problem with this as our parser strips away extra parentheses:
https://github.com/camfort/fortran-src/blob/master/src/Language/Fortran/Parser/Fortran90.y#L1027
However, this appears to be valid Fortran 90 code. I haven't been able to pin down when this was introduced into the language, but we should certainly do something about this!
Metadata
Assignees
Labels
No labels
Activity