summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/argument_checking_11.f90
blob: 7c70c37ee47b0de1de2205ee8c51c8664f155cb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
! { dg-do compile }
! { dg-options "-std=f95 -fmax-errors=100" }
!
! PR fortran/34665
!
! Test argument checking
!
! TODO: Check also expressions, e.g. "(a(1))" instead of "a(1)
! for strings; check also "string" and [ "string" ]
!
implicit none
CONTAINS
SUBROUTINE test1(a,b,c,d,e)
 integer, dimension(:) :: a
 integer, pointer, dimension(:) :: b
 integer, dimension(*) :: c
 integer, dimension(5) :: d
 integer               :: e

 call as_size(a)
 call as_size(b)
 call as_size(c)
 call as_size(d)
 call as_size(e) ! { dg-error "Rank mismatch" }
 call as_size(1) ! { dg-error "Rank mismatch" }
 call as_size( (/ 1 /) )
 call as_size( (a) )
 call as_size( (b) )
 call as_size( (c) ) ! { dg-error "The upper bound in the last dimension must appear in the reference to the assumed size array" }
 call as_size( (d) )
 call as_size( (e) ) ! { dg-error "Rank mismatch" }
 call as_size(a(1)) ! { dg-error "Element of assumed-shaped" }
 call as_size(b(1)) ! { dg-error "Element of assumed-shaped" }
 call as_size(c(1))
 call as_size(d(1))
 call as_size( (a(1)) ) ! { dg-error "Rank mismatch" }
 call as_size( (b(1)) ) ! { dg-error "Rank mismatch" }
 call as_size( (c(1)) ) ! { dg-error "Rank mismatch" }
 call as_size( (d(1)) ) ! { dg-error "Rank mismatch" }
 call as_size(a(1:2))
 call as_size(b(1:2))
 call as_size(c(1:2))
 call as_size(d(1:2))
 call as_size( (a(1:2)) )
 call as_size( (b(1:2)) )
 call as_size( (c(1:2)) )
 call as_size( (d(1:2)) )

 call as_shape(a)
 call as_shape(b)
 call as_shape(c) ! { dg-error "cannot be an assumed-size array" }
 call as_shape(d)
 call as_shape(e) ! { dg-error "Rank mismatch" }
 call as_shape( 1 ) ! { dg-error "Rank mismatch" }
 call as_shape( (/ 1 /) )
 call as_shape( (a) )
 call as_shape( (b) )
 call as_shape( (c) ) ! { dg-error "The upper bound in the last dimension must appear in the reference to the assumed size array" }
 call as_shape( (d) )
 call as_shape( (e) ) ! { dg-error "Rank mismatch" }
 call as_shape( (1) ) ! { dg-error "Rank mismatch" }
 call as_shape( ((/ 1 /)) )
 call as_shape(a(1)) ! { dg-error "Rank mismatch" }
 call as_shape(b(1)) ! { dg-error "Rank mismatch" }
 call as_shape(c(1)) ! { dg-error "Rank mismatch" }
 call as_shape(d(1)) ! { dg-error "Rank mismatch" }
 call as_shape( (a(1)) ) ! { dg-error "Rank mismatch" }
 call as_shape( (b(1)) ) ! { dg-error "Rank mismatch" }
 call as_shape( (c(1)) ) ! { dg-error "Rank mismatch" }
 call as_shape( (d(1)) ) ! { dg-error "Rank mismatch" }
 call as_shape(a(1:2))
 call as_shape(b(1:2))
 call as_shape(c(1:2))
 call as_shape(d(1:2))
 call as_shape( (a(1:2)) )
 call as_shape( (b(1:2)) )
 call as_shape( (c(1:2)) )
 call as_shape( (d(1:2)) )

 call as_expl(a)
 call as_expl(b)
 call as_expl(c)
 call as_expl(d)
 call as_expl(e) ! { dg-error "Rank mismatch" }
 call as_expl( 1 ) ! { dg-error "Rank mismatch" }
 call as_expl( (/ 1, 2, 3 /) )
 call as_expl( (a) )
 call as_expl( (b) )
 call as_expl( (c) ) ! { dg-error "The upper bound in the last dimension must appear in the reference to the assumed size array" }
 call as_expl( (d) )
 call as_expl( (e) ) ! { dg-error "Rank mismatch" }
 call as_expl(a(1)) ! { dg-error "Element of assumed-shaped" }
 call as_expl(b(1)) ! { dg-error "Element of assumed-shaped" }
 call as_expl(c(1))
 call as_expl(d(1))
 call as_expl( (a(1)) ) ! { dg-error "Rank mismatch" }
 call as_expl( (b(1)) ) ! { dg-error "Rank mismatch" }
 call as_expl( (c(1)) ) ! { dg-error "Rank mismatch" }
 call as_expl( (d(1)) )  ! { dg-error "Rank mismatch" }
 call as_expl(a(1:3))
 call as_expl(b(1:3))
 call as_expl(c(1:3))
 call as_expl(d(1:3))
 call as_expl( (a(1:3)) )
 call as_expl( (b(1:3)) )
 call as_expl( (c(1:3)) )
 call as_expl( (d(1:3)) )
END SUBROUTINE test1

SUBROUTINE as_size(a)
 integer, dimension(*) :: a
END SUBROUTINE as_size

SUBROUTINE as_shape(a)
 integer, dimension(:) :: a
END SUBROUTINE as_shape

SUBROUTINE as_expl(a)
 integer, dimension(3) :: a
END SUBROUTINE as_expl


SUBROUTINE test2(a,b,c,d,e)
 character(len=*), dimension(:) :: a
 character(len=*), pointer, dimension(:) :: b
 character(len=*), dimension(*) :: c
 character(len=*), dimension(5) :: d
 character(len=*)               :: e

 call cas_size(a)
 call cas_size(b)
 call cas_size(c)
 call cas_size(d)
 call cas_size(e) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size("abc") ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size( (/"abc"/) )
 call cas_size(a//"a")
 call cas_size(b//"a")
 call cas_size(c//"a")  ! { dg-error "The upper bound in the last dimension must appear in the reference to the assumed size array" }
 call cas_size(d//"a")
 call cas_size(e//"a") ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size(("abc")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size( ((/"abc"/)) )
 call cas_size(a(1)) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size(b(1)) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size(c(1)) ! OK in F95
 call cas_size(d(1)) ! OK in F95
 call cas_size((a(1)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" } 
 call cas_size((b(1)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size((c(1)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" } 
 call cas_size((d(1)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size(a(1:2))
 call cas_size(b(1:2))
 call cas_size(c(1:2))
 call cas_size(d(1:2))
 call cas_size((a(1:2)//"a"))
 call cas_size((b(1:2)//"a"))
 call cas_size((c(1:2)//"a"))
 call cas_size((d(1:2)//"a"))
 call cas_size(a(:)(1:3))
 call cas_size(b(:)(1:3))
 call cas_size(d(:)(1:3))
 call cas_size((a(:)(1:3)//"a"))
 call cas_size((b(:)(1:3)//"a"))
 call cas_size((d(:)(1:3)//"a"))
 call cas_size(a(1:2)(1:3))
 call cas_size(b(1:2)(1:3))
 call cas_size(c(1:2)(1:3))
 call cas_size(d(1:2)(1:3))
 call cas_size((a(1:2)(1:3)//"a"))
 call cas_size((b(1:2)(1:3)//"a"))
 call cas_size((c(1:2)(1:3)//"a"))
 call cas_size((d(1:2)(1:3)//"a"))
 call cas_size(e(1:3)) ! { dg-error "Fortran 2003: Scalar CHARACTER" } 
 call cas_size("abcd"(1:3)) ! { dg-error "Fortran 2003: Scalar CHARACTER" } 
 call cas_size((e(1:3))) ! { dg-error "Fortran 2003: Scalar CHARACTER" } 
 call cas_size(("abcd"(1:3)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" } 

 call cas_shape(a)
 call cas_shape(b)
 call cas_shape(c) ! { dg-error "cannot be an assumed-size array" }
 call cas_shape(d)
 call cas_shape(e) ! { dg-error "Rank mismatch" }
 call cas_shape("abc") ! { dg-error "Rank mismatch" }
 call cas_shape( (/"abc"/) )
 call cas_shape(a//"c")
 call cas_shape(b//"c")
 call cas_shape(c//"c") ! { dg-error "The upper bound in the last dimension must appear in the reference to the assumed size array" }
 call cas_shape(d//"c")
 call cas_shape(e//"c") ! { dg-error "Rank mismatch" }
 call cas_shape(("abc")) ! { dg-error "Rank mismatch" }
 call cas_shape( ((/"abc"/)) )
 call cas_shape(a(1)) ! { dg-error "Rank mismatch" }
 call cas_shape(b(1)) ! { dg-error "Rank mismatch" }
 call cas_shape(c(1)) ! { dg-error "Rank mismatch" }
 call cas_shape(d(1)) ! { dg-error "Rank mismatch" }
 call cas_shape(a(1:2))
 call cas_shape(b(1:2))
 call cas_shape(c(1:2))
 call cas_shape(d(1:2))
 call cas_shape((a(1:2)//"a"))
 call cas_shape((b(1:2)//"a"))
 call cas_shape((c(1:2)//"a"))
 call cas_shape((d(1:2)//"a"))
 call cas_shape(a(:)(1:3))
 call cas_shape(b(:)(1:3))
 call cas_shape(d(:)(1:3))
 call cas_shape((a(:)(1:3)//"a"))
 call cas_shape((b(:)(1:3)//"a"))
 call cas_shape((d(:)(1:3)//"a"))
 call cas_shape(a(1:2)(1:3))
 call cas_shape(b(1:2)(1:3))
 call cas_shape(c(1:2)(1:3))
 call cas_shape(d(1:2)(1:3))
 call cas_shape((a(1:2)(1:3)//"a"))
 call cas_shape((b(1:2)(1:3)//"a"))
 call cas_shape((c(1:2)(1:3)//"a"))
 call cas_shape((d(1:2)(1:3)//"a"))
 call cas_size(e(1:3)) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size("abcd"(1:3)) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size((e(1:3))) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_size(("abcd"(1:3)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }

 call cas_expl(a)
 call cas_expl(b)
 call cas_expl(c)
 call cas_expl(d)
 call cas_expl(e) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl("abc") ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl((/"a","b","c"/))
 call cas_expl(a//"a")
 call cas_expl(b//"a")
 call cas_expl(c//"a")  ! { dg-error "The upper bound in the last dimension must appear in the reference to the assumed size array" }
 call cas_expl(d//"a")
 call cas_expl(e//"a") ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl(("abc")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl(((/"a","b","c"/)))
 call cas_expl(a(1)) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl(b(1)) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl(c(1)) ! OK in F95
 call cas_expl(d(1)) ! OK in F95
 call cas_expl((a(1)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl((b(1)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl((c(1)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl((d(1)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl(a(1:3))
 call cas_expl(b(1:3))
 call cas_expl(c(1:3))
 call cas_expl(d(1:3))
 call cas_expl((a(1:3)//"a"))
 call cas_expl((b(1:3)//"a"))
 call cas_expl((c(1:3)//"a"))
 call cas_expl((d(1:3)//"a"))
 call cas_expl(a(:)(1:3))
 call cas_expl(b(:)(1:3))
 call cas_expl(d(:)(1:3))
 call cas_expl((a(:)(1:3)))
 call cas_expl((b(:)(1:3)))
 call cas_expl((d(:)(1:3)))
 call cas_expl(a(1:2)(1:3))
 call cas_expl(b(1:2)(1:3))
 call cas_expl(c(1:2)(1:3))
 call cas_expl(d(1:2)(1:3))
 call cas_expl((a(1:2)(1:3)//"a"))
 call cas_expl((b(1:2)(1:3)//"a"))
 call cas_expl((c(1:2)(1:3)//"a"))
 call cas_expl((d(1:2)(1:3)//"a"))
 call cas_expl(e(1:3)) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl("abcd"(1:3)) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl((e(1:3))) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
 call cas_expl(("abcd"(1:3)//"a")) ! { dg-error "Fortran 2003: Scalar CHARACTER" }
END SUBROUTINE test2

SUBROUTINE cas_size(a)
 character(len=*), dimension(*) :: a
END SUBROUTINE cas_size

SUBROUTINE cas_shape(a)
 character(len=*), dimension(:) :: a
END SUBROUTINE cas_shape

SUBROUTINE cas_expl(a)
 character(len=*), dimension(3) :: a
END SUBROUTINE cas_expl
END