1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Tests for the 14 items that specify a "specification expression" in section
5 ! a constant or subobject of a constant,
11 type(dType
), parameter :: dConst
= dType(3)
12 real, dimension(3) :: realVar1
13 real, dimension(dConst
%field
) :: realVar2
16 ! an object designator with a base object that is a dummy argument that has
17 ! neither the OPTIONAL nor the INTENT (OUT) attribute,
18 subroutine s2(inArg
, inoutArg
, outArg
, optArg
)
19 integer, intent(in
) :: inArg
20 integer, intent(inout
) :: inoutArg
21 integer, intent(out
) :: outArg
22 integer, intent(in
), optional
:: optArg
23 real, dimension(inArg
) :: realVar1
24 real, dimension(inoutArg
) :: realVar2
25 !ERROR: Invalid specification expression: reference to INTENT(OUT) dummy argument 'outarg'
26 real, dimension(outArg
) :: realVar3
27 !ERROR: Invalid specification expression: reference to OPTIONAL dummy argument 'optarg'
28 real, dimension(optArg
) :: realVar4
33 ! an object designator with a base object that is in a common block,
37 real, dimension(intCommonVar
) :: realVar
40 ! an object designator with a base object that is made accessible by
41 ! use or host association,
48 real, dimension(intVar
) :: realVar
51 ! an array constructor where each element and each scalar-int-expr of
52 ! each ac-implied-do-control is a restricted expression,
54 real, dimension(storage_size([1,2])) :: realVar
57 ! a structure constructor where each component is a restricted expression,
64 real, dimension(storage_size(dType(1, 2))) :: realArray
67 ! a specification inquiry where each designator or argument is
68 ! (a) a restricted expression or
70 real, dimension(3) :: realArray1
71 real, dimension(size(realArray1
)) :: realArray2
74 ! a specification inquiry where each designator or argument is
75 ! (b) a variable that is not an optional dummy argument, and whose
76 ! properties inquired about are not
77 ! (i) dependent on the upper bound of the last dimension of an
79 subroutine s7bi(assumedArg
)
80 integer, dimension(2, *) :: assumedArg
81 real, dimension(ubound(assumedArg
, 1)) :: realArray1
82 !ERROR: DIM=2 dimension is out of range for rank-2 assumed-size array
83 real, dimension(ubound(assumedArg
, 2)) :: realArray2
86 ! a specification inquiry where each designator or argument is
87 ! (b) a variable that is not an optional dummy argument, and whose
88 ! properties inquired about are not
90 subroutine s7bii(dummy
)
91 character(len
=:), pointer :: dummy
92 ! Should be an error since "dummy" is deferred, but all compilers handle it
93 real, dimension(len(dummy
)) :: realArray
96 ! a specification inquiry where each designator or argument is
97 ! (b) a variable that is not an optional dummy argument, and whose
98 ! properties inquired about are not
99 ! (iii) defined by an expression that is not a restricted expression,
100 subroutine s7biii(x
, y
)
101 real, intent(out
) :: x(:)
102 real, optional
:: y(:)
103 integer, parameter :: localConst
= 5
105 ! OK, since "localConst" is a constant
106 real, dimension(localConst
) :: realArray1
107 !ERROR: Invalid specification expression: reference to local entity 'local'
108 real, dimension(local
) :: realArray2
109 real, dimension(size(realArray1
)) :: realArray3
! ok
110 real, dimension(size(x
)) :: realArray4
! ok
111 real, dimension(merge(1,2,present(y
))) :: realArray5
! ok
112 !ERROR: Invalid specification expression: reference to OPTIONAL dummy argument 'y'
113 real, dimension(size(y
)) :: realArray6
114 end subroutine s7biii
116 ! a specification inquiry that is a constant expression,
119 real, dimension(bit_size(iVar
)) :: realArray
122 ! a reference to the intrinsic function PRESENT,
123 subroutine s9(optArg
)
124 integer, optional
:: optArg
125 real, dimension(merge(3, 4, present(optArg
))) :: realArray
128 ! a reference to any other standard intrinsic function where each
129 ! argument is a restricted expression,
132 real, dimension(bit_size(iVar
)) :: realArray
135 ! a reference to a transformational function from the intrinsic module
136 ! IEEE_ARITHMETIC, IEEE_EXCEPTIONS, or ISO_C_BINDING, where each argument
137 ! is a restricted expression,
140 real, dimension(merge(3, 4, ieee_support_halting(ieee_invalid
))) :: realArray
143 ! a reference to a specification function where each argument is a
144 ! restricted expression,
147 pure
function specFunc(arg
)
148 integer, intent(in
) :: arg
151 end function specFunc
156 real, dimension(specFunc(2)) :: realArray
159 ! a type parameter of the derived type being defined,
162 integer, len
:: param
163 real, dimension(param
) :: realField
167 ! an ac-do-variable within an array constructor where each
168 ! scalar-int-expr of the corresponding ac-implied-do-control is a restricted
171 real, dimension(5) :: realField
= [(i
, i
= 1, 5)]
174 ! a restricted expression enclosed in parentheses,where each subscript,
175 ! section subscript, substring starting point, substring ending point, and
176 ! type parameter value is a restricted expression
179 integer, len
:: param
180 real, dimension((param
+ 2)) :: realField
184 ! Regression test: don't get confused by host association
189 real, dimension(n
) :: r