340 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic2module m3 integer :: foo4 !Note: PGI, Intel, and GNU allow this; NAG and Sun do not5 !ERROR: 'foo' is already declared in this scoping unit6 interface foo7 end interface8end module9 10module m211 interface s12 end interface13contains14 !WARNING: 's' 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 subroutine s16 end subroutine17end module18 19module m320 ! This is okay: s is generic and specific21 interface s22 procedure s223 end interface24 interface s25 procedure s26 end interface27contains28 subroutine s()29 end subroutine30 subroutine s2(x)31 end subroutine32end module33 34module m4a35 interface g36 procedure s_real37 end interface38contains39 subroutine s_real(x)40 end41end42module m4b43 interface g44 procedure s_int45 end interface46contains47 subroutine s_int(i)48 end49end50! Generic g should merge the two use-associated ones51subroutine s452 use m4a53 use m4b54 call g(123)55 call g(1.2)56end57 58module m5a59 interface g60 procedure s_real61 end interface62contains63 subroutine s_real(x)64 end65end66module m5b67 interface gg68 procedure s_int69 end interface70contains71 subroutine s_int(i)72 end73end74! Generic g should merge the two use-associated ones75subroutine s576 use m5a77 use m5b, g => gg78 call g(123)79 call g(1.2)80end81 82module m6a83 interface gg84 procedure sa85 end interface86contains87 subroutine sa(x)88 end89end90module m6b91 interface gg92 procedure sb93 end interface94contains95 subroutine sb(y)96 end97end98subroutine s699 !ERROR: Generic 'g' may not have specific procedures 'sa' and 'sb' as their interfaces are not distinguishable100 use m6a, g => gg101 use m6b, g => gg102end103 104module m7a105 interface g106 procedure s1107 end interface108contains109 subroutine s1(x)110 end111end112module m7b113 interface g114 procedure s2115 end interface116contains117 subroutine s2(x, y)118 end119end120module m7c121 interface g122 procedure s3123 end interface124contains125 subroutine s3(x, y, z)126 end127end128! Merge the three use-associated generics129subroutine s7130 use m7a131 use m7b132 use m7c133 call g(1.0)134 call g(1.0, 2.0)135 call g(1.0, 2.0, 3.0)136end137 138module m8a139 interface g140 procedure s1141 end interface142contains143 subroutine s1(x)144 end145end146module m8b147 interface g148 procedure s2149 end interface150contains151 subroutine s2(x, y)152 end153end154module m8c155 integer :: g156end157! If merged generic conflicts with another USE, it is an error (if it is referenced)158subroutine s8159 use m8a160 use m8b161 use m8c162 !ERROR: Reference to 'g' is ambiguous163 g = 1164end165 166module m9a167 interface g168 module procedure g169 end interface170contains171 subroutine g()172 end173end module174module m9b175 interface g176 module procedure g177 end interface178contains179 subroutine g()180 end181end module182subroutine s9183 !PORTABILITY: USE-associated generic 'g' should not have specific procedures 'g' and 'g' as their interfaces are not distinguishable184 use m9a185 use m9b186end187 188module m10a189 interface g190 module procedure s191 end interface192 private :: s193contains194 subroutine s(x)195 integer :: x196 end197end198module m10b199 use m10a200 !ERROR: Generic 'g' may not have specific procedures 's' and 's' as their interfaces are not distinguishable201 interface g202 module procedure s203 end interface204 private :: s205contains206 subroutine s(x)207 integer :: x208 end209end210 211module m12a212 interface ga213 module procedure sa214 end interface215contains216 subroutine sa(i)217 end218end219module m12b220 use m12a221 interface gb222 module procedure sb223 end interface224contains225 subroutine sb(x)226 end227end228module m12c229 use m12b, only: gc => gb230end231module m12d232 use m12a, only: g => ga233 use m12c, only: g => gc234 interface g235 end interface236end module237 238module m13a239 contains240 subroutine subr241 end subroutine242end module243module m13b244 use m13a245 interface subr246 module procedure subr247 end interface248end module249module m13c250 use m13a251 use m13b252 contains253 subroutine test254 call subr255 end subroutine256end module257module m13d258 use m13b259 use m13a260 contains261 subroutine test262 call subr263 end subroutine264end module265 266module m14a267 type :: foo268 integer :: n269 end type270end module271module m14b272 interface foo273 module procedure bar274 end interface275 contains276 real function bar(x)277 real, intent(in) :: x278 bar = x279 end function280end module281module m14c282 use m14a283 use m14b284 type(foo) :: x285end module286module m14d287 use m14a288 use m14b289 type(foo) :: x290 contains291 subroutine test292 real :: y293 !PORTABILITY: Reference to generic function 'foo' (resolving to specific 'bar') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]294 y = foo(1.0)295 x = foo(2)296 end subroutine297end module298module m14e299 use m14b300 use m14a301 type(foo) :: x302 contains303 subroutine test304 real :: y305 !PORTABILITY: Reference to generic function 'foo' (resolving to specific 'bar') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]306 y = foo(1.0)307 x = foo(2)308 end subroutine309end module310 311module m15a312 interface foo313 module procedure bar314 end interface315 contains316 subroutine bar317 end subroutine318end module319module m15b320 !ERROR: Cannot use-associate 'foo'; it is already declared in this scope321 use m15a322 contains323 subroutine foo324 end subroutine325end module326module m15c327 contains328 subroutine foo329 end subroutine330end module331module m15d332 use m15a333 use m15c334 contains335 subroutine test336 !ERROR: Reference to 'foo' is ambiguous337 call foo338 end subroutine339end module340