[PATCH] PR fortran/97408 - Diagnose non-constant KIND argument to intrinsics
Harald Anlauf
anlauf@gmx.de
Wed Oct 14 20:16:46 GMT 2020
[Resending with CC:fortran]
Hi Tobias,
> I don't know whether it is valid – I just find it not obvious that [(i,
> i=1,5)] is valid and [(int(1, kind=i), i=1,1)] is not.
10.1.12 Constant expression
A constant expression is an expression with limitations that make it suitable for use as a kind type parameter,
initializer, or named constant. It is an expression in which each operation is intrinsic, and each primary is
(1) a constant or subobject of a constant,
(2) an array constructor where each element and each scalar-int-expr of each ac-implied-do-control is a
constant expression,
[...]
and
7.8 Construction of array values
R775 ac-implied-do-control is [ integer-type-spec :: ] ac-do-variable = scalar-int-expr , scalar-int-expr [ , scalar-int-expr ]
This at least explains why [(i,i=1,5)] is valid.
> Surely, if one first expands the array, it is valid: "[integer ::
> (int(i, kind=i), i=1,2)]" → "[integer :: int(1, kind=1), int(2,kind=2)]"
> → "[integer :: 1_1, 2_2]" → "[1,2]".
Do you know by chance where the standard says sth. that the expansion you
describe is how things are to be interpreted?
Of course, without the typespec integer :: the constructor is invalid by:
C7110 (R770) If type-spec is omitted, each ac-value expression in the array-constructor shall have the same declared type and kind type parameters.
If type-spec is omitted, corresponding length type parameters of the declared type of each ac-value expression
shall have the same value; in this case, the declared type and type parameters of the array constructor are those
of the ac-value expressions.
Which might mean that a later check on the type parameters of the elements of the array constructor should/would catch this.
And the present PR is possibly invalid.
Harald
More information about the Fortran
mailing list