1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! 15.4.3.4.5 Restrictions on generic declarations
3 ! Specific procedures of generic interfaces must be distinguishable.
6 !ERROR: Generic 'g' may not have specific procedures 's2' and 's4' as their interfaces are not distinguishable
28 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
39 !ERROR: Generic 'g' may not have specific procedures 'f1' and 'f2' as their interfaces are not distinguishable
51 type, extends(t1
) :: t2
65 ! These are all different ranks so they are distinguishable
82 !ERROR: Generic 'g' may not have specific procedures 's1' and 's4' as their interfaces are not distinguishable
91 !ERROR: Generic 'g' may not have specific procedures 's1' and 's5' as their interfaces are not distinguishable
92 !ERROR: Generic 'g' may not have specific procedures 's2' and 's5' as their interfaces are not distinguishable
93 !ERROR: Generic 'g' may not have specific procedures 's3' and 's5' as their interfaces are not distinguishable
101 ! Two procedures that differ only by attributes are not distinguishable
103 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
105 pure
subroutine s1(x
)
106 real, intent(in
) :: x
109 real, intent(in
) :: x
115 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
127 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
141 real, pointer, intent(out
) :: x
144 real, allocatable
:: x
147 !ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable
150 real, pointer, intent(in
) :: x
153 real, allocatable
:: x
159 !ERROR: Generic 'g1' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
160 generic
:: g1
=> s1
, s2
! rank-1 and assumed-rank
161 !ERROR: Generic 'g2' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
162 generic
:: g2
=> s2
, s3
! scalar and assumed-rank
163 !ERROR: Generic 'g3' may not have specific procedures 's1' and 's4' as their interfaces are not distinguishable
164 generic
:: g3
=> s1
, s4
! different shape, same rank
180 ! Procedures that are distinguishable by return type of a dummy argument
192 procedure(real), pointer :: x
195 procedure(integer), pointer :: x
200 procedure(real), pointer :: x
206 ! Check user-defined operators
208 interface operator(*)
212 !ERROR: Generic 'OPERATOR(+)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable
213 interface operator(+)
217 interface operator(.foo
.)
221 !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable
222 interface operator(.bar
.)
227 real function f1(x
, y
)
228 real, intent(in
) :: x
229 logical, intent(in
) :: y
231 integer function f2(x
, y
)
232 integer, intent(in
) :: x
233 logical, intent(in
) :: y
235 real function f3(x
, y
)
241 ! Types distinguished by kind (but not length) parameters
244 integer, kind
:: k1
= 1
245 integer, len
:: l1
= 101
248 type, extends(t1
) :: t2(k2a
, l2
, k2b
)
249 integer, kind
:: k2a
= 2
250 integer, kind
:: k2b
= 3
251 integer, len
:: l2
= 102
254 type, extends(t2
) :: t3(l3
, k3
)
255 integer, kind
:: k3
= 4
256 integer, len
:: l3
= 103
263 !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
268 !ERROR: Generic 'g3' may not have specific procedures 's4' and 's5' as their interfaces are not distinguishable
288 !ERROR: Generic 'g7' may not have specific procedures 's6' and 's7' as their interfaces are not distinguishable
293 !ERROR: Generic 'g8' may not have specific procedures 's6' and 's8' as their interfaces are not distinguishable
298 !ERROR: Generic 'g9' may not have specific procedures 's7' and 's8' as their interfaces are not distinguishable
315 type(t3(1, 101, 2, 102, 3, 103, 4)) :: x
321 type(t3(1, 99, k2b
=2, k2a
=3, l2
=*, l3
=103, k3
=4)) :: x
324 type(t3(k1
=1, l1
=99, k2a
=3, k2b
=2, k3
=4)) :: x
327 type(t3(1, :, 3, :, 2, :, 4)), allocatable
:: x
334 ! Check that specifics for type-bound generics can be distinguished
338 procedure
, nopass
:: s1
339 procedure
, nopass
:: s2
340 procedure
, nopass
:: s3
341 generic
:: g1
=> s1
, s2
342 !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
343 generic
:: g2
=> s1
, s3
357 ! Check polymorphic types
361 type, extends(t
) :: t1
363 type, extends(t
) :: t2
365 type, extends(t2
) :: t2a
371 !ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable
380 !ERROR: Generic 'g4' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
385 !ERROR: Generic 'g5' may not have specific procedures 's2' and 's5' as their interfaces are not distinguishable
390 !ERROR: Generic 'g6' may not have specific procedures 's2' and 's6' as their interfaces are not distinguishable
416 ! Test C1514 rule 3 -- distinguishable passed-object dummy arguments
421 procedure
, pass(x
) :: p1
=> s
422 procedure
, pass
:: p2
=> s
424 procedure
, pass(y
) :: p4
=> s
425 generic
:: g1
=> p1
, p4
426 generic
:: g2
=> p2
, p4
427 generic
:: g3
=> p3
, p4
436 ! C1511 - rules for operators
438 interface operator(.foo
.)
442 !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f2' and 'f3' as their interfaces are not distinguishable
443 interface operator(.bar
.)
448 integer function f1(i
)
449 integer, intent(in
) :: i
451 integer function f2(i
, j
)
452 integer, value
:: i
, j
454 integer function f3(i
, j
)
455 integer, intent(in
) :: i
, j
460 interface operator(.not
.)
462 character(*),intent(in
) :: x
465 interface operator(+)
472 interface operator(.not
.)
473 !ERROR: Procedure 'f' from module 'm20' is already specified in generic 'OPERATOR(.NOT.)'
476 interface operator(+)
477 !ERROR: Procedure 'f' from module 'm20' is already specified in generic 'OPERATOR(+)'
482 ! Extensions for distinguishable allocatable arguments; these should not
483 ! elicit errors from f18
488 procedure s1a
, s1b
! only one is polymorphic
491 procedure s2a
, s2b
! only one is unlimited polymorphic
495 type(t
), allocatable
:: x
498 class(t
), allocatable
:: x
501 class(t
), allocatable
:: x
504 class(*), allocatable
:: x