The index of an implied DO loop in a DATA statement or array constructor is defined by Fortran 2018 to have scope over its implied DO loop. This definition is unfortunate, because it requires the implied DO loop's bounds expressions to be in the scope of the index variable. Consequently, in code like integer, parameter :: j = 5 real, save :: a(5) = [(j, j=1, j)] the upper bound of the loop is a reference to the index variable, not the parameter in the enclosing scope. This patch limits the scope of the index variable to the "body" of the implied DO loop as one would naturally expect, with a warning. I would have preferred to make this a hard error, but most Fortran compilers treat this case as f18 now does. If the standard were to be fixed, the warning could be made optional. Differential Revision: https://reviews.llvm.org/D108595
10 lines
480 B
Fortran
10 lines
480 B
Fortran
! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols %s 2>&1 | FileCheck %s
|
|
! CHECK: Implied DO index 'j' uses an object of the same name in its bounds expressions
|
|
! CHECK: ObjectEntity type: REAL(4) shape: 1_8:5_8 init:[REAL(4)::1._4,2._4,3._4,4._4,5._4]
|
|
! Verify that the scope of a DATA statement implied DO loop index does
|
|
! not include the bounds expressions (language extension, with warning)
|
|
integer, parameter :: j = 5
|
|
real, save :: a(j)
|
|
data (a(j),j=1,j)/1,2,3,4,5/
|
|
end
|