1 ! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
2 ! Check out-of-range subscripts
4 real a(10), da(2,1), empty(1:0,1)
5 integer, parameter :: n(2) = [1, 2]
7 !ERROR: DATA statement designator 'a(0_8)' is out of range
8 !ERROR: DATA statement designator 'a(11_8)' is out of range
9 data a(0)/0./, a(10+1)/0./
10 !ERROR: Subscript 0 is less than lower bound 1 for dimension 1 of array
12 !ERROR: Subscript 0 is less than lower bound 1 for dimension 1 of array
14 !ERROR: Subscript 11 is greater than upper bound 10 for dimension 1 of array
16 !ERROR: Subscript 11 is greater than upper bound 10 for dimension 1 of array
18 !ERROR: Subscript value (0) is out of range on dimension 1 in reference to a constant array value
20 !ERROR: Subscript value (3) is out of range on dimension 1 in reference to a constant array value
22 print *, a(1:12:3) ! ok
23 !ERROR: Subscript 13 is greater than upper bound 10 for dimension 1 of array
25 print *, a(10:-1:-3) ! ok
26 !ERROR: Subscript -2 is less than lower bound 1 for dimension 1 of array
28 print *, a(-1:-2) ! empty section is ok
29 print *, a(0:11:-1) ! empty section is ok
30 !ERROR: Subscript 0 is less than lower bound 1 for dimension 1 of array
31 print *, a(0:0:unknown
) ! lower==upper, can ignore stride
32 !ERROR: Subscript 11 is greater than upper bound 10 for dimension 1 of array
33 print *, a(11:11:unknown
) ! lower==upper, can ignore stride
34 !ERROR: Subscript 0 is less than lower bound 1 for dimension 1 of array
36 !ERROR: Subscript 3 is greater than upper bound 2 for dimension 1 of array
38 !ERROR: Subscript 0 is less than lower bound 1 for dimension 2 of array
40 !WARNING: Subscript 2 is greater than upper bound 1 for dimension 2 of array
42 print *, empty([(j
,j
=1,0)],1) ! ok
43 print *, empty(1:0,1) ! ok
44 print *, empty(:,1) ! ok
45 print *, empty(i
:j
,k
) ! ok
46 !WARNING: Empty array dimension 1 should not be subscripted as an element or non-empty array section