374 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12module m13 implicit none4contains5 subroutine foo(x)6 real :: x7 end subroutine8end module9 10!Note: PGI, Intel, GNU, and NAG allow this; Sun does not11module m212 use m113 implicit none14 !WARNING: 'foo' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic [-Whomonymous-specific]15 interface foo16 module procedure s17 end interface18contains19 subroutine s(i)20 integer :: i21 end subroutine22end module23 24subroutine foo25 !PORTABILITY: 'foo' is use-associated into a subprogram of the same name [-Wuse-association-into-same-name-subprogram]26 use m127 !ERROR: Reference to 'foo' is ambiguous28 call foo29end30 31subroutine bar32 !PORTABILITY: 'foo' is use-associated into a subprogram of the same name [-Wuse-association-into-same-name-subprogram]33 use m1, bar => foo34 !ERROR: Reference to 'bar' is ambiguous35 call bar36end37 38!OK to use-associate a type with the same name as a generic39module m3a40 type :: foo41 end type42end43module m3b44 use m3a45 interface foo46 end interface47end48 49! Can't have derived type and function with same name50module m4a51 type :: foo52 end type53contains54 !ERROR: 'foo' is already declared in this scoping unit55 function foo(x)56 end57end58! Even if there is also a generic interface of that name59module m4b60 type :: foo61 end type62 interface foo63 procedure :: foo64 end interface foo65contains66 !ERROR: 'foo' is already declared in this scoping unit67 function foo(x)68 end69end70module m4c71 type :: foo72 end type73 interface foo74 !ERROR: 'foo' is already declared in this scoping unit75 real function foo()76 end function foo77 end interface foo78end79 80! Use associating a name that is a generic and a derived type81module m5a82 interface g83 end interface84 type g85 end type86end module87module m5b88 use m5a89 interface g90 procedure f91 end interface92 type(g) :: x93contains94 function f(i)95 end function96end module97subroutine s598 use m5b99 type(g) :: y100end101 102module m6103 real :: f6104 interface g6105 !ERROR: 'f6' is already declared in this scoping unit106 real function f6()107 end function f6108 end interface g6109end module m6110 111module m7112 integer :: f7113 interface g7114 !ERROR: 'f7' is already declared in this scoping unit115 real function f7()116 end function f7117 end interface g7118end module m7119 120module m8121 real :: f8122 interface g8123 !ERROR: 'f8' is already declared in this scoping unit124 subroutine f8()125 end subroutine f8126 end interface g8127end module m8128 129module m9130 type f9131 end type f9132 interface f9133 real function f9()134 end function f9135 end interface f9136contains137 !ERROR: 'f9' is already declared in this scoping unit138 function f9(x)139 end function f9140end module m9141 142module m10143 type :: t10144 end type t10145 interface f10146 function f10()147 end function f10148 end interface f10149contains150 !ERROR: 'f10' is already declared in this scoping unit151 function f10(x)152 end function f10153end module m10154 155module m11156 type :: t11157 end type t11158 interface i11159 function f11()160 end function f11161 end interface i11162contains163 !ERROR: 'f11' is already declared in this scoping unit164 function f11(x)165 end function f11166end module m11167 168module m12169 interface f12170 function f12()171 end function f12172 end interface f12173contains174 !ERROR: 'f12' is already declared in this scoping unit175 function f12(x)176 end function f12177end module m12178 179module m13180 interface f13181 function f13()182 end function f13183 end interface f13184contains185 !ERROR: 'f13' is already declared in this scoping unit186 function f13()187 end function f13188end module m13189 190! Not an error191module m14192 interface gen1193 module procedure s194 end interface195 generic :: gen2 => s196 contains197 subroutine s(x)198 integer(1) :: x199 end subroutine s200end module m14201module m15202 use m14203 interface gen1204 module procedure gen1205 end interface206 generic :: gen2 => gen2207 contains208 subroutine gen1(x)209 integer(2) :: x210 end subroutine gen1211 subroutine gen2(x)212 integer(4) :: x213 end subroutine gen2214end module m15215 216module m15a217 interface foo218 module procedure foo219 end interface220 contains221 function foo()222 end223end224 225module m15b226 interface foo227 module procedure foo228 end interface229 contains230 function foo(x)231 end232end233 234subroutine test15235 use m15a236 use m15b ! ok237end238 239 240module m16a241 type foo242 integer j243 end type244 interface foo245 module procedure bar246 end interface247 contains248 function bar(j)249 end250end251 252module m16b253 type foo254 integer j, k255 end type256 interface foo257 module procedure bar258 end interface259 contains260 function bar(x,y)261 end262end263 264subroutine test16265 use m16a266 use m16b ! ok267end268 269subroutine test17270 use m15a271 use m16a ! ok272end273 274subroutine test18275 use m16a276 use m15a ! ok277end278 279module m21280 type foo281 integer a282 end type283 interface foo284 module procedure f1285 end interface286 contains287 function f1(a)288 f1 = a289 end290end291 292module m22293 type foo294 real b295 end type296 interface foo297 module procedure f2298 end interface299 contains300 function f2(a,b)301 f2 = a + b302 end303end304 305module m23306 interface foo307 module procedure foo308 module procedure f3309 end interface310 contains311 function foo()312 foo = 0.313 end314 function f3(a,b,c)315 f3 = a + b + c316 end317end318 319module m24320 interface foo321 module procedure foo322 module procedure f4323 end interface324 contains325 function foo(a)326 foo = a327 end328 function f4(a,b,c,d)329 f4 = a + b + c +d330 end331end332 333subroutine s_21_22_a334 use m21335 use m22336 print *, foo(1.) ! Intel error337 print *, foo(1.,2.) ! Intel error338end339 340subroutine s_21_22_b341 use m21342 use m22343 !ERROR: 'foo' is not a derived type344 type(foo) x ! definite error: GNU and Intel catch345end346 347subroutine s_21_23348 use m21349 use m23350 type(foo) x ! Intel and NAG error351 !PORTABILITY: Reference to generic function 'foo' (resolving to specific 'f1') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]352 print *, foo(1.) ! Intel error353 print *, foo(1.,2.,3.) ! Intel error354 call ext(foo) ! GNU and Intel error355end356 357subroutine s_22_23358 use m22359 use m23360 type(foo) x ! Intel and NAG error361 print *, foo(1.,2.) ! Intel error362 print *, foo(1.,2.,3.) ! Intel error363 call ext(foo) ! Intel error364end365 366subroutine s_23_24367 use m23368 use m24369 print *, foo(1.,2.,3.) ! NAG error370 print *, foo(1.,2.,3.,4.) ! XLF error371 !ERROR: 'foo' is not a specific procedure372 call ext(foo) ! definite error373end374