C7115: why is this constraint necessary?

Fortran 2018 constraint C7115 prohibits the use of the same array constructor implied DO loop index name at multiple levels of a nest of implied DO loops. But array constructor implied DO loop indexes are “statement entities” with scope, and can appear in multiple implied DO loops in the same array constructor so long as they don’t nest, and can have distinct types. So why the prohibition against the name duplication?

(DATA statement implied DO loops do not have an analogous constraint, although ifort and nagfor both enforce one. I/O statement implied DO loops do have an analogous constraint, but it makes sense because they aren’t statement entities and can be referenced after the statement.)

It is to forbid such things as
[((i*i, i=1,15),i=1,21)]
what i is used in i*i?

C7115 certainly precludes that example, but there’s no ambiguity; the scope of the inner i shadows the outer one.

1 Like

In an inner loop you want to reference the value of the loop index of an outer loop.

do j = 1,N
do i = 1,N
a(i,j) = b(i,j)
end do
end do

Same idea applies to array constructor loops.

Array constructor implied DO loop indices have scope over their bodies. Regular DO loop indices do not.