On 7/3/26 08:46, Jerry D wrote:
Hi all,

As I have been looking at PR103367, I was questioning again about the warnings we give for reals as array indexes and as DO variables.

While I am at it here, should we make those hard errors and only allow with a warning with -std=legacy. Will we end up breaking a bunch of old codes by doing this?


There are two issues here.  The first one is array indices.  The
Fortran standard has never allowed REAL types.

F66, 5.1.3.3:

A subscript expression is written as one the following constructs:
   c*v+k, c*v-k, c*v, v+k, v-k, v, k
where c and k are integer constants and v is an integer variable
reference.

F77, 5.4.2 Subscript Expression

A subscription expression is an integer expression.

F90, 6.2.2 Array elements and array sections
...
R617 subscript           is scalar-int-expr
R618 section-subscript   is subscript
                         or subscript-triplet
                         or vector-subscript
R619  subscript-triplet  is [ subscript ] : [ subscript ] [ : stride ]
R620  stride             is scalar-int-expr
R621  vector-subscript   is int-expr

IMHO, gfortran should issue a hard error for a non-integer index.



The second issue is a poor choice from F77.

F66, 7.1.2.8:

   DO n i = m1, m2, m3
or
   DO n i = m1, m2
...
(2) i is an integer variable, ...
(3) m1 ..., m2 ..., m3 ..., are each either an integer constant or
    integer variable reference.


F77, 11.10 DO statement

The form of a DO statment is

   DO s [,] i = e1, e2 [, e3]
...

i is the name of an integer, real or double precision variable ...
e1, e2, and e3 are each an integer, real or double precision expression

The F90 standard committee saw the error in the above.

F90, 8.1.4.1.1 Form of the block DO construct
...
R821 loop-control  is [ , ] do-variable = scalar-numeric-expr ,
                      scalar-numeric-expr [ , scalar-numeric-expr ]
                   or ...
R822 do-variable   is scalar-variable

Constraint: The do-variable must be a named scalar variable of
   type integer, ***default real, or double precision real.***

Constraint: Each scalar-numeric-expr in loop-control must be of
 type integer, ***default real, or double precision real.***

The *** ...  *** denotes the Obsolescent lower case font.

B.2 Obsolescent features
...
(2) Real and double precision DO control variables and DO loop
    control expressions -- use integer (8.1.4.1)

The committee moved this (mis)feature to the Deleted Features
list in Fortran 95.

So, gfortran should accept REAL DO control variables and
control expressions with -std=legacy.  Issuing a warning
would seem to be appropriate even with the -std=legacy
option.

--
steve




Reply via email to