brintos

brintos / llvm-project-archived public Read only

0
0
Text · 12.2 KiB · 0ab4b7c Raw
531 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic2! 15.4.3.4.5 Restrictions on generic declarations3! Specific procedures of generic interfaces must be distinguishable.4 5module m16  !ERROR: Generic 'g' may not have specific procedures 's2' and 's4' as their interfaces are not distinguishable7  interface g8    procedure s19    procedure s210    procedure s311    procedure s412  end interface13contains14  subroutine s1(x)15    integer(8) x16  end17  subroutine s2(x)18    integer x19  end20  subroutine s321  end22  subroutine s4(x)23    integer x24  end25end26 27module m228  !ERROR: Generic 'g' may not have specific procedures 'm2s1' and 'm2s2' as their interfaces are not distinguishable29  interface g30    subroutine m2s1(x)31    end subroutine32    subroutine m2s2(x)33      real x34    end subroutine35  end interface36end37 38module m339  !ERROR: Generic 'g' may not have specific procedures 'm3f1' and 'm3f2' as their interfaces are not distinguishable40  interface g41    integer function m3f1()42    end function43    real function m3f2()44    end function45  end interface46end47 48module m449  type :: t150  end type51  type, extends(t1) :: t252  end type53  interface g54    subroutine m4s1(x)55      import :: t156      type(t1) :: x57    end58    subroutine m4s2(x)59      import :: t260      type(t2) :: x61    end62  end interface63end64 65! These are all different ranks so they are distinguishable66module m567  interface g68    subroutine m5s1(x)69      real x70    end subroutine71    subroutine m5s2(x)72      real x(:)73    end subroutine74    subroutine m5s3(x)75      real x(:,:)76    end subroutine77  end interface78end79 80module m681  use m582  !ERROR: Generic 'g' may not have specific procedures 'm5s1' and 'm6s4' as their interfaces are not distinguishable83  interface g84    subroutine m6s4(x)85    end subroutine86  end interface87end88 89module m790  use m591  !ERROR: Generic 'g' may not have specific procedures 'm5s1' and 'm7s5' as their interfaces are not distinguishable92  !ERROR: Generic 'g' may not have specific procedures 'm5s2' and 'm7s5' as their interfaces are not distinguishable93  !ERROR: Generic 'g' may not have specific procedures 'm5s3' and 'm7s5' as their interfaces are not distinguishable94  interface g95    subroutine m7s5(x)96      real x(..)97    end subroutine98  end interface99end100 101! Two procedures that differ only by attributes are not distinguishable102module m8103  !ERROR: Generic 'g' may not have specific procedures 'm8s1' and 'm8s2' as their interfaces are not distinguishable104  interface g105    pure subroutine m8s1(x)106      real, intent(in) :: x107    end subroutine108    subroutine m8s2(x)109      real, intent(in) :: x110    end subroutine111  end interface112end113 114module m9115  !ERROR: Generic 'g' may not have specific procedures 'm9s1' and 'm9s2' as their interfaces are not distinguishable116  interface g117    subroutine m9s1(x)118      real :: x(10)119    end subroutine120    subroutine m9s2(x)121      real :: x(100)122    end subroutine123  end interface124end125 126module m10127  !ERROR: Generic 'g' may not have specific procedures 'm10s1' and 'm10s2' as their interfaces are not distinguishable128  interface g129    subroutine m10s1(x)130      real :: x(10)131    end subroutine132    subroutine m10s2(x)133      real :: x(..)134    end subroutine135  end interface136end137 138program m11139  interface g1140    subroutine m11s1(x)141      real, pointer, intent(out) :: x142    end subroutine143    subroutine m11s2(x)144      real, allocatable :: x145    end subroutine146  end interface147  !ERROR: Generic 'g2' may not have specific procedures 'm11s3' and 'm11s4' as their interfaces are not distinguishable148  interface g2149    subroutine m11s3(x)150      real, pointer, intent(in) :: x151    end subroutine152    subroutine m11s4(x)153      real, allocatable :: x154    end subroutine155  end interface156end157 158module m12159  !ERROR: Generic 'g1' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable160  generic :: g1 => s1, s2  ! rank-1 and assumed-rank161  !ERROR: Generic 'g2' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable162  generic :: g2 => s2, s3  ! scalar and assumed-rank163  !ERROR: Generic 'g3' may not have specific procedures 's1' and 's4' as their interfaces are not distinguishable164  generic :: g3 => s1, s4  ! different shape, same rank165contains166  subroutine s1(x)167    real :: x(10)168  end169  subroutine s2(x)170    real :: x(..)171  end172  subroutine s3(x)173    real :: x174  end175  subroutine s4(x)176    real :: x(100)177  end178end179 180! Procedures that are distinguishable by return type of a dummy argument181module m13182  interface g1183    procedure s1184    procedure s2185  end interface186  interface g2187    procedure s1188    procedure s3189  end interface190contains191  subroutine s1(x)192    procedure(real), pointer :: x193  end194  subroutine s2(x)195    procedure(integer), pointer :: x196  end197  subroutine s3(x)198    interface199      function x()200        procedure(real), pointer :: x201      end function202    end interface203  end204end205 206! Check user-defined operators207module m14208  interface operator(*)209    module procedure f1210    module procedure f2211  end interface212  !ERROR: Generic 'OPERATOR(+)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable213  interface operator(+)214    module procedure f1215    module procedure f3216  end interface217  interface operator(.foo.)218    module procedure f1219    module procedure f2220  end interface221  !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable222  interface operator(.bar.)223    module procedure f1224    module procedure f3225  end interface226contains227  real function f1(x, y)228    real, intent(in) :: x229    logical, intent(in) :: y230    f1 = 0.231  end232  integer function f2(x, y)233    integer, intent(in) :: x234    logical, intent(in) :: y235    f2 = 0.236  end237  real function f3(x, y)238    real, value :: x239    logical, value :: y240    f3 = 0.241  end242end module243 244! Types distinguished by kind (but not length) parameters245module m15246  type :: t1(k1, l1)247    integer, kind :: k1 = 1248    integer, len :: l1 = 101249  end type250 251  type, extends(t1) :: t2(k2a, l2, k2b)252    integer, kind :: k2a = 2253    integer, kind :: k2b = 3254    integer, len :: l2 = 102255  end type256 257  type, extends(t2) :: t3(l3, k3)258    integer, kind :: k3 = 4259    integer, len :: l3 = 103260  end type261 262  interface g1263    procedure s1264    procedure s2265  end interface266  !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable267  interface g2268    procedure s1269    procedure s3270  end interface271  !ERROR: Generic 'g3' may not have specific procedures 's4' and 's5' as their interfaces are not distinguishable272  interface g3273    procedure s4274    procedure s5275  end interface276  interface g4277    procedure s5278    procedure s6279    procedure s9280  end interface281  interface g5282    procedure s4283    procedure s7284    procedure s9285  end interface286  interface g6287    procedure s5288    procedure s8289    procedure s9290  end interface291  !ERROR: Generic 'g7' may not have specific procedures 's6' and 's7' as their interfaces are not distinguishable292  interface g7293    procedure s6294    procedure s7295  end interface296  !ERROR: Generic 'g8' may not have specific procedures 's6' and 's8' as their interfaces are not distinguishable297  interface g8298    procedure s6299    procedure s8300  end interface301  !ERROR: Generic 'g9' may not have specific procedures 's7' and 's8' as their interfaces are not distinguishable302  interface g9303    procedure s7304    procedure s8305  end interface306 307contains308  subroutine s1(x)309    type(t1(1, 5)) :: x310  end311  subroutine s2(x)312    type(t1(2, 4)) :: x313  end314  subroutine s3(x)315    type(t1(l1=5)) :: x316  end317  subroutine s4(x)318    type(t3(1, 101, 2, 102, 3, 103, 4)) :: x319  end subroutine320  subroutine s5(x)321    type(t3) :: x322  end subroutine323  subroutine s6(x)324    type(t3(1, 99, k2b=2, k2a=3, l2=*, l3=103, k3=4)) :: x325  end subroutine326  subroutine s7(x)327    type(t3(k1=1, l1=99, k2a=3, k2b=2, k3=4)) :: x328  end subroutine329  subroutine s8(x)330    type(t3(1, :, 3, :, 2, :, 4)), allocatable :: x331  end subroutine332  subroutine s9(x)333    type(t3(k1=2)) :: x334  end subroutine335end336 337! Check that specifics for type-bound generics can be distinguished338module m16339  type :: t340  contains341    procedure, nopass :: s1342    procedure, nopass :: s2343    procedure, nopass :: s3344    generic :: g1 => s1, s2345    !ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable346    generic :: g2 => s1, s3347  end type348contains349  subroutine s1(x)350    real :: x351  end352  subroutine s2(x)353    integer :: x354  end355  subroutine s3(x)356    real :: x357  end358end359 360! Check polymorphic types361module m17362  type :: t363  end type364  type, extends(t) :: t1365  end type366  type, extends(t) :: t2367  end type368  type, extends(t2) :: t2a369  end type370  interface g1371    procedure s1372    procedure s2373  end interface374  !ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable375  interface g2376    procedure s3377    procedure s4378  end interface379  interface g3380    procedure s1381    procedure s4382  end interface383  !ERROR: Generic 'g4' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable384  interface g4385    procedure s2386    procedure s3387  end interface388  !ERROR: Generic 'g5' may not have specific procedures 's2' and 's5' as their interfaces are not distinguishable389  interface g5390    procedure s2391    procedure s5392  end interface393  !ERROR: Generic 'g6' may not have specific procedures 's2' and 's6' as their interfaces are not distinguishable394  interface g6395    procedure s2396    procedure s6397  end interface398contains399  subroutine s1(x)400    type(t) :: x401  end402  subroutine s2(x)403    type(t2a) :: x404  end405  subroutine s3(x)406    class(t) :: x407  end408  subroutine s4(x)409    class(t2) :: x410  end411  subroutine s5(x)412    class(*) :: x413  end414  subroutine s6(x)415    type(*) :: x416  end417end418 419! Test C1514 rule 3 -- distinguishable passed-object dummy arguments420module m18421  type :: t(k)422    integer, kind :: k423  contains424    procedure, pass(x) :: p1 => s425    procedure, pass    :: p2 => s426    procedure          :: p3 => s427    procedure, pass(y) :: p4 => s428    generic :: g1 => p1, p4429    generic :: g2 => p2, p4430    generic :: g3 => p3, p4431  end type432contains433  subroutine s(x, y)434    class(t(1)) :: x435    class(t(2)) :: y436  end437end438 439! C1511 - rules for operators440module m19441  interface operator(.foo.)442    module procedure f1443    module procedure f2444  end interface445  !ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f2' and 'f3' as their interfaces are not distinguishable446  interface operator(.bar.)447    module procedure f2448    module procedure f3449  end interface450contains451  integer function f1(i)452    integer, intent(in) :: i453    f1 = 0454  end455  integer function f2(i, j)456    integer, value :: i, j457    f2 = 0458  end459  integer function f3(i, j)460    integer, intent(in) :: i, j461    f3 = 0462  end463end464 465module m20466  interface operator(.not.)467    real function m20f(x)468      character(*),intent(in) :: x469    end function470  end interface471  interface operator(+)472    procedure m20f473  end interface474end module475 476subroutine subr1()477  use m20478  interface operator(.not.)479    !ERROR: Procedure 'm20f' from module 'm20' is already specified in generic 'OPERATOR(.NOT.)'480    procedure m20f481  end interface482  interface operator(+)483    !ERROR: Procedure 'm20f' from module 'm20' is already specified in generic 'OPERATOR(+)'484    procedure m20f485  end interface486end subroutine subr1487 488! Extensions for distinguishable allocatable arguments; these should not489! elicit errors from f18490module m21491  type :: t492  end type493  interface int1494    procedure s1a, s1b ! only one is polymorphic495  end interface496  interface int2497    procedure s2a, s2b ! only one is unlimited polymorphic498  end interface499 contains500  subroutine s1a(x)501    type(t), allocatable :: x502  end subroutine503  subroutine s1b(x)504    class(t), allocatable :: x505  end subroutine506  subroutine s2a(x)507    class(t), allocatable :: x508  end subroutine509  subroutine s2b(x)510    class(*), allocatable :: x511  end subroutine512end module513 514! Example reduced from pFUnit515module m22516  !PORTABILITY: Generic 'generic' should not have specific procedures 'sub1' and 'sub2' as their interfaces are not distinguishable by the rules in the standard517  interface generic518    procedure sub1, sub2519  end interface520 contains521  subroutine sub1(b, c)522    class(*) b523    integer, optional :: c524  end525  subroutine sub2(a, b, c)526    real a527    class(*) b528    integer, optional :: c529  end530end531