1 ! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
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 'm2s1' and 'm2s2' as their interfaces are not distinguishable
39 !ERROR: Generic 'g' may not have specific procedures 'm3f1' and 'm3f2' as their interfaces are not distinguishable
41 integer function m3f1()
51 type, extends(t1
) :: t2
65 ! These are all different ranks so they are distinguishable
82 !ERROR: Generic 'g' may not have specific procedures 'm5s1' and 'm6s4' as their interfaces are not distinguishable
91 !ERROR: Generic 'g' may not have specific procedures 'm5s1' and 'm7s5' as their interfaces are not distinguishable
92 !ERROR: Generic 'g' may not have specific procedures 'm5s2' and 'm7s5' as their interfaces are not distinguishable
93 !ERROR: Generic 'g' may not have specific procedures 'm5s3' and 'm7s5' 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 'm8s1' and 'm8s2' as their interfaces are not distinguishable
105 pure
subroutine m8s1(x
)
106 real, intent(in
) :: x
109 real, intent(in
) :: x
115 !ERROR: Generic 'g' may not have specific procedures 'm9s1' and 'm9s2' as their interfaces are not distinguishable
127 !ERROR: Generic 'g' may not have specific procedures 'm10s1' and 'm10s2' 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 'm11s3' and 'm11s4' 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
232 integer function f2(x
, y
)
233 integer, intent(in
) :: x
234 logical, intent(in
) :: y
237 real function f3(x
, y
)
244 ! Types distinguished by kind (but not length) parameters
247 integer, kind
:: k1
= 1
248 integer, len
:: l1
= 101
251 type, extends(t1
) :: t2(k2a
, l2
, k2b
)
252 integer, kind
:: k2a
= 2
253 integer, kind
:: k2b
= 3
254 integer, len
:: l2
= 102
257 type, extends(t2
) :: t3(l3
, k3
)
258 integer, kind
:: k3
= 4
259 integer, len
:: l3
= 103
266 !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
271 !ERROR: Generic 'g3' may not have specific procedures 's4' and 's5' as their interfaces are not distinguishable
291 !ERROR: Generic 'g7' may not have specific procedures 's6' and 's7' as their interfaces are not distinguishable
296 !ERROR: Generic 'g8' may not have specific procedures 's6' and 's8' as their interfaces are not distinguishable
301 !ERROR: Generic 'g9' may not have specific procedures 's7' and 's8' as their interfaces are not distinguishable
318 type(t3(1, 101, 2, 102, 3, 103, 4)) :: x
324 type(t3(1, 99, k2b
=2, k2a
=3, l2
=*, l3
=103, k3
=4)) :: x
327 type(t3(k1
=1, l1
=99, k2a
=3, k2b
=2, k3
=4)) :: x
330 type(t3(1, :, 3, :, 2, :, 4)), allocatable
:: x
337 ! Check that specifics for type-bound generics can be distinguished
341 procedure
, nopass
:: s1
342 procedure
, nopass
:: s2
343 procedure
, nopass
:: s3
344 generic
:: g1
=> s1
, s2
345 !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
346 generic
:: g2
=> s1
, s3
360 ! Check polymorphic types
364 type, extends(t
) :: t1
366 type, extends(t
) :: t2
368 type, extends(t2
) :: t2a
374 !ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable
383 !ERROR: Generic 'g4' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
388 !ERROR: Generic 'g5' may not have specific procedures 's2' and 's5' as their interfaces are not distinguishable
393 !ERROR: Generic 'g6' may not have specific procedures 's2' and 's6' as their interfaces are not distinguishable
419 ! Test C1514 rule 3 -- distinguishable passed-object dummy arguments
424 procedure
, pass(x
) :: p1
=> s
425 procedure
, pass
:: p2
=> s
427 procedure
, pass(y
) :: p4
=> s
428 generic
:: g1
=> p1
, p4
429 generic
:: g2
=> p2
, p4
430 generic
:: g3
=> p3
, p4
439 ! C1511 - rules for operators
441 interface operator(.foo
.)
445 !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f2' and 'f3' as their interfaces are not distinguishable
446 interface operator(.bar
.)
451 integer function f1(i
)
452 integer, intent(in
) :: i
455 integer function f2(i
, j
)
456 integer, value
:: i
, j
459 integer function f3(i
, j
)
460 integer, intent(in
) :: i
, j
466 interface operator(.not
.)
467 real function m20f(x
)
468 character(*),intent(in
) :: x
471 interface operator(+)
478 interface operator(.not
.)
479 !ERROR: Procedure 'm20f' from module 'm20' is already specified in generic 'OPERATOR(.NOT.)'
482 interface operator(+)
483 !ERROR: Procedure 'm20f' from module 'm20' is already specified in generic 'OPERATOR(+)'
488 ! Extensions for distinguishable allocatable arguments; these should not
489 ! elicit errors from f18
494 procedure s1a
, s1b
! only one is polymorphic
497 procedure s2a
, s2b
! only one is unlimited polymorphic
501 type(t
), allocatable
:: x
504 class(t
), allocatable
:: x
507 class(t
), allocatable
:: x
510 class(*), allocatable
:: x
514 ! Example reduced from pFUnit
516 !PORTABILITY: Generic 'generic' should not have specific procedures 'sub1' and 'sub2' as their interfaces are not distinguishable by the rules in the standard
521 subroutine sub1(b
, c
)
523 integer, optional
:: c
525 subroutine sub2(a
, b
, c
)
528 integer, optional
:: c