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
102 ! Two procedures that differ only by attributes are not distinguishable
104 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
106 pure
subroutine s1(x
)
107 real, intent(in
) :: x
110 real, intent(in
) :: x
116 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
128 !ERROR: Generic 'g' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
142 real, pointer, intent(out
) :: x
145 real, allocatable
:: x
148 !ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable
151 real, pointer, intent(in
) :: x
154 real, allocatable
:: x
160 !ERROR: Generic 'g1' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
161 generic
:: g1
=> s1
, s2
! rank-1 and assumed-rank
162 !ERROR: Generic 'g2' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
163 generic
:: g2
=> s2
, s3
! scalar and assumed-rank
164 !ERROR: Generic 'g3' may not have specific procedures 's1' and 's4' as their interfaces are not distinguishable
165 generic
:: g3
=> s1
, s4
! different shape, same rank
181 ! Procedures that are distinguishable by return type of a dummy argument
193 procedure(real), pointer :: x
196 procedure(integer), pointer :: x
201 procedure(real), pointer :: x
207 ! Check user-defined operators
209 interface operator(*)
213 !ERROR: Generic 'OPERATOR(+)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable
214 interface operator(+)
218 interface operator(.foo
.)
222 !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable
223 interface operator(.bar
.)
228 real function f1(x
, y
)
229 real, intent(in
) :: x
230 logical, intent(in
) :: y
232 integer function f2(x
, y
)
233 integer, intent(in
) :: x
234 logical, intent(in
) :: y
236 real function f3(x
, y
)
242 ! Types distinguished by kind (but not length) parameters
245 integer, kind
:: k1
= 1
246 integer, len
:: l1
= 101
249 type, extends(t1
) :: t2(k2a
, l2
, k2b
)
250 integer, kind
:: k2a
= 2
251 integer, kind
:: k2b
= 3
252 integer, len
:: l2
= 102
255 type, extends(t2
) :: t3(l3
, k3
)
256 integer, kind
:: k3
= 4
257 integer, len
:: l3
= 103
264 !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
269 !ERROR: Generic 'g3' may not have specific procedures 's4' and 's5' as their interfaces are not distinguishable
289 !ERROR: Generic 'g7' may not have specific procedures 's6' and 's7' as their interfaces are not distinguishable
294 !ERROR: Generic 'g8' may not have specific procedures 's6' and 's8' as their interfaces are not distinguishable
299 !ERROR: Generic 'g9' may not have specific procedures 's7' and 's8' as their interfaces are not distinguishable
316 type(t3(1, 101, 2, 102, 3, 103, 4)) :: x
322 type(t3(1, 99, k2b
=2, k2a
=3, l2
=*, l3
=103, k3
=4)) :: x
325 type(t3(k1
=1, l1
=99, k2a
=3, k2b
=2, k3
=4)) :: x
328 type(t3(1, :, 3, :, 2, :, 4)), allocatable
:: x
335 ! Check that specifics for type-bound generics can be distinguished
339 procedure
, nopass
:: s1
340 procedure
, nopass
:: s2
341 procedure
, nopass
:: s3
342 generic
:: g1
=> s1
, s2
343 !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
344 generic
:: g2
=> s1
, s3
358 ! Check polymorphic types
362 type, extends(t
) :: t1
364 type, extends(t
) :: t2
366 type, extends(t2
) :: t2a
372 !ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable
381 !ERROR: Generic 'g4' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
386 !ERROR: Generic 'g5' may not have specific procedures 's2' and 's5' as their interfaces are not distinguishable
391 !ERROR: Generic 'g6' may not have specific procedures 's2' and 's6' as their interfaces are not distinguishable
417 ! Test C1514 rule 3 -- distinguishable passed-object dummy arguments
422 procedure
, pass(x
) :: p1
=> s
423 procedure
, pass
:: p2
=> s
425 procedure
, pass(y
) :: p4
=> s
426 generic
:: g1
=> p1
, p4
427 generic
:: g2
=> p2
, p4
428 generic
:: g3
=> p3
, p4
437 ! C1511 - rules for operators
439 interface operator(.foo
.)
443 !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f2' and 'f3' as their interfaces are not distinguishable
444 interface operator(.bar
.)
449 integer function f1(i
)
450 integer, intent(in
) :: i
452 integer function f2(i
, j
)
453 integer, value
:: i
, j
455 integer function f3(i
, j
)
456 integer, intent(in
) :: i
, j
461 interface operator(.not
.)
463 character(*),intent(in
) :: x
466 interface operator(+)
473 interface operator(.not
.)
474 !ERROR: Procedure 'f' from module 'm20' is already specified in generic 'OPERATOR(.NOT.)'
477 interface operator(+)
478 !ERROR: Procedure 'f' from module 'm20' is already specified in generic 'OPERATOR(+)'
483 ! Extensions for distinguishable allocatable arguments; these should not
484 ! elicit errors from f18
489 procedure s1a
, s1b
! only one is polymorphic
492 procedure s2a
, s2b
! only one is unlimited polymorphic
496 type(t
), allocatable
:: x
499 class(t
), allocatable
:: x
502 class(t
), allocatable
:: x
505 class(*), allocatable
:: x