1 ! RUN: %S/test_errors.sh %s %t %flang_fc1
3 ! 15.4.3.4.5 Restrictions on generic declarations
4 ! Specific procedures of generic interfaces must be distinguishable.
7 !ERROR: Generic 'g' may not have specific procedures 's2' and 's4' as their interfaces are not distinguishable
29 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
40 !ERROR: Generic 'g' may not have specific procedures 'f1' and 'f2' as their interfaces are not distinguishable
52 type, extends(t1
) :: t2
66 ! These are all different ranks so they are distinguishable
83 !ERROR: Generic 'g' may not have specific procedures 's1' and 's4' as their interfaces are not distinguishable
92 !ERROR: Generic 'g' may not have specific procedures 's1' and 's5' as their interfaces are not distinguishable
93 !ERROR: Generic 'g' may not have specific procedures 's2' and 's5' as their interfaces are not distinguishable
94 !ERROR: Generic 'g' may not have specific procedures 's3' and 's5' as their interfaces are not distinguishable
103 ! Two procedures that differ only by attributes are not distinguishable
105 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
107 pure
subroutine s1(x
)
108 real, intent(in
) :: x
111 real, intent(in
) :: x
117 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
129 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
143 real, pointer, intent(out
) :: x
146 real, allocatable
:: x
149 !ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable
152 real, pointer, intent(in
) :: x
155 real, allocatable
:: x
161 !ERROR: Generic 'g1' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
162 generic
:: g1
=> s1
, s2
! rank-1 and assumed-rank
163 !ERROR: Generic 'g2' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
164 generic
:: g2
=> s2
, s3
! scalar and assumed-rank
165 !ERROR: Generic 'g3' may not have specific procedures 's1' and 's4' as their interfaces are not distinguishable
166 generic
:: g3
=> s1
, s4
! different shape, same rank
182 ! Procedures that are distinguishable by return type of a dummy argument
194 procedure(real), pointer :: x
197 procedure(integer), pointer :: x
202 procedure(real), pointer :: x
208 ! Check user-defined operators
210 interface operator(*)
214 !ERROR: Generic 'OPERATOR(+)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable
215 interface operator(+)
219 interface operator(.foo
.)
223 !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable
224 interface operator(.bar
.)
229 real function f1(x
, y
)
230 real, intent(in
) :: x
231 logical, intent(in
) :: y
233 integer function f2(x
, y
)
234 integer, intent(in
) :: x
235 logical, intent(in
) :: y
237 real function f3(x
, y
)
243 ! Types distinguished by kind (but not length) parameters
246 integer, kind
:: k1
= 1
247 integer, len
:: l1
= 101
250 type, extends(t1
) :: t2(k2a
, l2
, k2b
)
251 integer, kind
:: k2a
= 2
252 integer, kind
:: k2b
= 3
253 integer, len
:: l2
= 102
256 type, extends(t2
) :: t3(l3
, k3
)
257 integer, kind
:: k3
= 4
258 integer, len
:: l3
= 103
265 !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
270 !ERROR: Generic 'g3' may not have specific procedures 's4' and 's5' as their interfaces are not distinguishable
290 !ERROR: Generic 'g7' may not have specific procedures 's6' and 's7' as their interfaces are not distinguishable
295 !ERROR: Generic 'g8' may not have specific procedures 's6' and 's8' as their interfaces are not distinguishable
300 !ERROR: Generic 'g9' may not have specific procedures 's7' and 's8' as their interfaces are not distinguishable
317 type(t3(1, 101, 2, 102, 3, 103, 4)) :: x
323 type(t3(1, 99, k2b
=2, k2a
=3, l2
=*, l3
=103, k3
=4)) :: x
326 type(t3(k1
=1, l1
=99, k2a
=3, k2b
=2, k3
=4)) :: x
329 type(t3(1, :, 3, :, 2, :, 4)), allocatable
:: x
336 ! Check that specifics for type-bound generics can be distinguished
340 procedure
, nopass
:: s1
341 procedure
, nopass
:: s2
342 procedure
, nopass
:: s3
343 generic
:: g1
=> s1
, s2
344 !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
345 generic
:: g2
=> s1
, s3
359 ! Check polymorphic types
363 type, extends(t
) :: t1
365 type, extends(t
) :: t2
367 type, extends(t2
) :: t2a
373 !ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable
382 !ERROR: Generic 'g4' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
387 !ERROR: Generic 'g5' may not have specific procedures 's2' and 's5' as their interfaces are not distinguishable
392 !ERROR: Generic 'g6' may not have specific procedures 's2' and 's6' as their interfaces are not distinguishable
418 ! Test C1514 rule 3 -- distinguishable passed-object dummy arguments
423 procedure
, pass(x
) :: p1
=> s
424 procedure
, pass
:: p2
=> s
426 procedure
, pass(y
) :: p4
=> s
427 generic
:: g1
=> p1
, p4
428 generic
:: g2
=> p2
, p4
429 generic
:: g3
=> p3
, p4
438 ! C1511 - rules for operators
440 interface operator(.foo
.)
444 !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f2' and 'f3' as their interfaces are not distinguishable
445 interface operator(.bar
.)
450 integer function f1(i
)
451 integer, intent(in
) :: i
453 integer function f2(i
, j
)
454 integer, value
:: i
, j
456 integer function f3(i
, j
)
457 integer, intent(in
) :: i
, j
462 interface operator(.not
.)
464 character(*),intent(in
) :: x
467 interface operator(+)
474 interface operator(.not
.)
475 !ERROR: Procedure 'f' from module 'm20' is already specified in generic 'OPERATOR(.NOT.)'
478 interface operator(+)
479 !ERROR: Procedure 'f' from module 'm20' is already specified in generic 'OPERATOR(+)'