In FORALL assignment, using a forall statement, or a forall construct, the index variable or variables should retain the defined/undefined status (and value if defined) they have at the start of the statement when the forall assignment is completed.
So in the following code, if i is undefined at the start it is undefined at the end, and if i = 4 (say) at the start then i = 4 at the end.
integer i
...
forall(i=1:10)
x(i) = ...
end forall
This seems to be treated correctly. Essentially the index variables have a different scope to the local ones. This 'rule' means the following code, in which the forall is nested inside a DO loop with the same index, is perfectly legal.
program main
integer i
real b(5)
real :: a(5) = (/1.0, 2.0, 3.0, 4.0, 5.0/)
b = 0.0
! Should be able to nest forall inside do loop and use same index variable
do i=1,2
! forall doesn't change defined/undefined status (or value if defined) of i
forall(i=1:5)
b(i) = b(i) + a(i)
end forall
end do
! should print 3
print *, i
! should print 2.0, 4.0, 6.0, ...
print *, b
end program main
However, the compiler generates **error 953 - i is already being used as a do (or implied do) index **. If I make the compiler ignore the error using /IGNORE 953, the code compiles and prints the correct value for i of 3 (it works properly even with /CHECKMATE turned on). This means the compiler will do the correct thing if the error message can be subverted.
Can forall indices be eliminated from the check for error 953? I realise this is not an important bug, just something you might see how to address easily at some time in the future.
Regards, David.