1! RUN: %S/test_errors.sh %s %t %flang_fc1
2! REQUIRES: shell
3! Test 15.5.2.4 constraints and restrictions for non-POINTER non-ALLOCATABLE
4! dummy arguments.
5
6module m01
7  type :: t
8  end type
9  type :: pdt(n)
10    integer, len :: n
11  end type
12  type :: pdtWithDefault(n)
13    integer, len :: n = 3
14  end type
15  type :: tbp
16   contains
17    procedure :: binding => subr01
18  end type
19  type :: final
20   contains
21    final :: subr02
22  end type
23  type :: alloc
24    real, allocatable :: a(:)
25  end type
26  type :: ultimateCoarray
27    real, allocatable :: a[:]
28  end type
29
30 contains
31
32  subroutine subr01(this)
33    class(tbp), intent(in) :: this
34  end subroutine
35  subroutine subr02(this)
36    type(final), intent(inout) :: this
37  end subroutine
38
39  subroutine poly(x)
40    class(t), intent(in) :: x
41  end subroutine
42  subroutine polyassumedsize(x)
43    class(t), intent(in) :: x(*)
44  end subroutine
45  subroutine assumedsize(x)
46    real :: x(*)
47  end subroutine
48  subroutine assumedrank(x)
49    real :: x(..)
50  end subroutine
51  subroutine assumedtypeandsize(x)
52    type(*) :: x(*)
53  end subroutine
54  subroutine assumedshape(x)
55    real :: x(:)
56  end subroutine
57  subroutine contiguous(x)
58    real, contiguous :: x(:)
59  end subroutine
60  subroutine intentout(x)
61    real, intent(out) :: x
62  end subroutine
63  subroutine intentinout(x)
64    real, intent(in out) :: x
65  end subroutine
66  subroutine asynchronous(x)
67    real, asynchronous :: x
68  end subroutine
69  subroutine asynchronousValue(x)
70    real, asynchronous, value :: x
71  end subroutine
72  subroutine volatile(x)
73    real, volatile :: x
74  end subroutine
75  subroutine pointer(x)
76    real, pointer :: x(:)
77  end subroutine
78  subroutine valueassumedsize(x)
79    real, intent(in) :: x(*)
80  end subroutine
81  subroutine volatileassumedsize(x)
82    real, volatile :: x(*)
83  end subroutine
84  subroutine volatilecontiguous(x)
85    real, volatile :: x(*)
86  end subroutine
87
88  subroutine test01(x) ! 15.5.2.4(2)
89    class(t), intent(in) :: x[*]
90    !ERROR: Coindexed polymorphic object may not be associated with a polymorphic dummy argument 'x='
91    call poly(x[1])
92  end subroutine
93
94  subroutine mono(x)
95    type(t), intent(in) :: x
96  end subroutine
97  subroutine test02(x) ! 15.5.2.4(2)
98    class(t), intent(in) :: x(*)
99    !ERROR: Assumed-size polymorphic array may not be associated with a monomorphic dummy argument 'x='
100    call mono(x)
101  end subroutine
102
103  subroutine typestar(x)
104    type(*), intent(in) :: x
105  end subroutine
106  subroutine test03 ! 15.5.2.4(2)
107    type(pdt(0)) :: x
108    !ERROR: Actual argument associated with TYPE(*) dummy argument 'x=' may not have a parameterized derived type
109    call typestar(x)
110  end subroutine
111
112  subroutine test04 ! 15.5.2.4(2)
113    type(tbp) :: x
114    !ERROR: Actual argument associated with TYPE(*) dummy argument 'x=' may not have type-bound procedure 'binding'
115    call typestar(x)
116  end subroutine
117
118  subroutine test05 ! 15.5.2.4(2)
119    type(final) :: x
120    !ERROR: Actual argument associated with TYPE(*) dummy argument 'x=' may not have derived type 'final' with FINAL subroutine 'subr02'
121    call typestar(x)
122  end subroutine
123
124  subroutine ch2(x)
125    character(2), intent(in out) :: x
126  end subroutine
127  subroutine pdtdefault (derivedArg)
128    !ERROR: Type parameter 'n' lacks a value and has no default
129    type(pdt) :: derivedArg
130  end subroutine pdtdefault
131  subroutine pdt3 (derivedArg)
132    type(pdt(4)) :: derivedArg
133  end subroutine pdt3
134  subroutine pdt4 (derivedArg)
135    type(pdt(*)) :: derivedArg
136  end subroutine pdt4
137  subroutine pdtWithDefaultDefault (derivedArg)
138    type(pdtWithDefault) :: derivedArg
139  end subroutine pdtWithDefaultdefault
140  subroutine pdtWithDefault3 (derivedArg)
141    type(pdtWithDefault(4)) :: derivedArg
142  end subroutine pdtWithDefault3
143  subroutine pdtWithDefault4 (derivedArg)
144    type(pdtWithDefault(*)) :: derivedArg
145  end subroutine pdtWithDefault4
146  subroutine test06 ! 15.5.2.4(4)
147    !ERROR: Type parameter 'n' lacks a value and has no default
148    type(pdt) :: vardefault
149    type(pdt(3)) :: var3
150    type(pdt(4)) :: var4
151    type(pdtWithDefault) :: defaultVardefault
152    type(pdtWithDefault(3)) :: defaultVar3
153    type(pdtWithDefault(4)) :: defaultVar4
154    character :: ch1
155    ! The actual argument is converted to a padded expression.
156    !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' must be definable
157    call ch2(ch1)
158    call pdtdefault(vardefault)
159    call pdtdefault(var3)
160    call pdtdefault(var4) ! error
161    call pdt3(vardefault) ! error
162    !ERROR: Actual argument type 'pdt(n=3_4)' is not compatible with dummy argument type 'pdt(n=4_4)'
163    call pdt3(var3) ! error
164    call pdt3(var4)
165    call pdt4(vardefault)
166    call pdt4(var3)
167    call pdt4(var4)
168    call pdtWithDefaultdefault(defaultVardefault)
169    call pdtWithDefaultdefault(defaultVar3)
170    !ERROR: Actual argument type 'pdtwithdefault(n=4_4)' is not compatible with dummy argument type 'pdtwithdefault(n=3_4)'
171    call pdtWithDefaultdefault(defaultVar4) ! error
172    !ERROR: Actual argument type 'pdtwithdefault(n=3_4)' is not compatible with dummy argument type 'pdtwithdefault(n=4_4)'
173    call pdtWithDefault3(defaultVardefault) ! error
174    !ERROR: Actual argument type 'pdtwithdefault(n=3_4)' is not compatible with dummy argument type 'pdtwithdefault(n=4_4)'
175    call pdtWithDefault3(defaultVar3) ! error
176    call pdtWithDefault3(defaultVar4)
177    call pdtWithDefault4(defaultVardefault)
178    call pdtWithDefault4(defaultVar3)
179    call pdtWithDefault4(defaultVar4)
180  end subroutine
181
182  subroutine out01(x)
183    type(alloc) :: x
184  end subroutine
185  subroutine test07(x) ! 15.5.2.4(6)
186    type(alloc) :: x[*]
187    !ERROR: Coindexed actual argument with ALLOCATABLE ultimate component '%a' must be associated with a dummy argument 'x=' with VALUE or INTENT(IN) attributes
188    call out01(x[1])
189  end subroutine
190
191  subroutine test08(x) ! 15.5.2.4(13)
192    real :: x(1)[*]
193    !ERROR: Coindexed scalar actual argument must be associated with a scalar dummy argument 'x='
194    call assumedsize(x(1)[1])
195  end subroutine
196
197  subroutine charray(x)
198    character :: x(10)
199  end subroutine
200  subroutine test09(ashape, polyarray, c) ! 15.5.2.4(14), 15.5.2.11
201    real :: x, arr(10)
202    real, pointer :: p(:)
203    real :: ashape(:)
204    class(t) :: polyarray(*)
205    character(10) :: c(:)
206    !ERROR: Whole scalar actual argument may not be associated with a dummy argument 'x=' array
207    call assumedsize(x)
208    !ERROR: Scalar POINTER target may not be associated with a dummy argument 'x=' array
209    call assumedsize(p(1))
210    !ERROR: Element of assumed-shape array may not be associated with a dummy argument 'x=' array
211    call assumedsize(ashape(1))
212    !ERROR: Polymorphic scalar may not be associated with a dummy argument 'x=' array
213    call polyassumedsize(polyarray(1))
214    call charray(c(1:1))  ! not an error if character
215    call assumedsize(arr(1))  ! not an error if element in sequence
216    call assumedrank(x)  ! not an error
217    call assumedtypeandsize(x)  ! not an error
218  end subroutine
219
220  subroutine test10(a) ! 15.5.2.4(16)
221    real :: scalar, matrix(2,3)
222    real :: a(*)
223    !ERROR: Scalar actual argument may not be associated with assumed-shape dummy argument 'x='
224    call assumedshape(scalar)
225    !ERROR: Rank of dummy argument is 1, but actual argument has rank 2
226    call assumedshape(matrix)
227    !ERROR: Assumed-size array may not be associated with assumed-shape dummy argument 'x='
228    call assumedshape(a)
229  end subroutine
230
231  subroutine test11(in) ! C15.5.2.4(20)
232    real, intent(in) :: in
233    real :: x
234    x = 0.
235    !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' must be definable
236    call intentout(in)
237    !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' must be definable
238    call intentout(3.14159)
239    !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' must be definable
240    call intentout(in + 1.)
241    call intentout(x) ! ok
242    !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' must be definable
243    call intentout((x))
244    !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'count=' must be definable
245    call system_clock(count=2)
246    !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' must be definable
247    call intentinout(in)
248    !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' must be definable
249    call intentinout(3.14159)
250    !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' must be definable
251    call intentinout(in + 1.)
252    call intentinout(x) ! ok
253    !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' must be definable
254    call intentinout((x))
255    !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'exitstat=' must be definable
256    call execute_command_line(command="echo hello", exitstat=0)
257  end subroutine
258
259  subroutine test12 ! 15.5.2.4(21)
260    real :: a(1)
261    integer :: j(1)
262    j(1) = 1
263    !ERROR: Actual argument associated with INTENT(OUT) dummy argument 'x=' must be definable
264    call intentout(a(j))
265    !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'x=' must be definable
266    call intentinout(a(j))
267    !ERROR: Actual argument associated with ASYNCHRONOUS dummy argument 'x=' must be definable
268    call asynchronous(a(j))
269    !ERROR: Actual argument associated with VOLATILE dummy argument 'x=' must be definable
270    call volatile(a(j))
271  end subroutine
272
273  subroutine coarr(x)
274    type(ultimateCoarray):: x
275  end subroutine
276  subroutine volcoarr(x)
277    type(ultimateCoarray), volatile :: x
278  end subroutine
279  subroutine test13(a, b) ! 15.5.2.4(22)
280    type(ultimateCoarray) :: a
281    type(ultimateCoarray), volatile :: b
282    call coarr(a)  ! ok
283    call volcoarr(b)  ! ok
284    !ERROR: VOLATILE attribute must match for dummy argument 'x=' when actual argument has a coarray ultimate component '%a'
285    call coarr(b)
286    !ERROR: VOLATILE attribute must match for dummy argument 'x=' when actual argument has a coarray ultimate component '%a'
287    call volcoarr(a)
288  end subroutine
289
290  subroutine test14(a,b,c,d) ! C1538
291    real :: a[*]
292    real, asynchronous :: b[*]
293    real, volatile :: c[*]
294    real, asynchronous, volatile :: d[*]
295    call asynchronous(a[1])  ! ok
296    call volatile(a[1])  ! ok
297    call asynchronousValue(b[1])  ! ok
298    call asynchronousValue(c[1])  ! ok
299    call asynchronousValue(d[1])  ! ok
300    !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE
301    call asynchronous(b[1])
302    !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE
303    call volatile(b[1])
304    !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE
305    call asynchronous(c[1])
306    !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE
307    call volatile(c[1])
308    !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE
309    call asynchronous(d[1])
310    !ERROR: Coindexed ASYNCHRONOUS or VOLATILE actual argument may not be associated with dummy argument 'x=' with ASYNCHRONOUS or VOLATILE attributes unless VALUE
311    call volatile(d[1])
312  end subroutine
313
314  subroutine test15() ! C1539
315    real, pointer :: a(:)
316    real, asynchronous :: b(10)
317    real, volatile :: c(10)
318    real, asynchronous, volatile :: d(10)
319    call assumedsize(a(::2)) ! ok
320    call contiguous(a(::2)) ! ok
321    call valueassumedsize(a(::2)) ! ok
322    call valueassumedsize(b(::2)) ! ok
323    call valueassumedsize(c(::2)) ! ok
324    call valueassumedsize(d(::2)) ! ok
325    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
326    call volatileassumedsize(b(::2))
327    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
328    call volatilecontiguous(b(::2))
329    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
330    call volatileassumedsize(c(::2))
331    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
332    call volatilecontiguous(c(::2))
333    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
334    call volatileassumedsize(d(::2))
335    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
336    call volatilecontiguous(d(::2))
337  end subroutine
338
339  subroutine test16() ! C1540
340    real, pointer :: a(:)
341    real, asynchronous, pointer :: b(:)
342    real, volatile, pointer :: c(:)
343    real, asynchronous, volatile, pointer :: d(:)
344    call assumedsize(a) ! ok
345    call contiguous(a) ! ok
346    call pointer(a) ! ok
347    call pointer(b) ! ok
348    call pointer(c) ! ok
349    call pointer(d) ! ok
350    call valueassumedsize(a) ! ok
351    call valueassumedsize(b) ! ok
352    call valueassumedsize(c) ! ok
353    call valueassumedsize(d) ! ok
354    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
355    call volatileassumedsize(b)
356    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
357    call volatilecontiguous(b)
358    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
359    call volatileassumedsize(c)
360    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
361    call volatilecontiguous(c)
362    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
363    call volatileassumedsize(d)
364    !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous dummy argument 'x='
365    call volatilecontiguous(d)
366  end subroutine
367
368end module
369