1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
|
! RUN: %python %S/test_errors.py %s %flang_fc1
! 15.4.3.4.5 Restrictions on generic declarations
! Specific procedures of generic interfaces must be distinguishable.
module m1
!ERROR: Generic 'g' may not have specific procedures 's2' and 's4' as their interfaces are not distinguishable
interface g
procedure s1
procedure s2
procedure s3
procedure s4
end interface
contains
subroutine s1(x)
integer(8) x
end
subroutine s2(x)
integer x
end
subroutine s3
end
subroutine s4(x)
integer x
end
end
module m2
!ERROR: Generic 'g' may not have specific procedures 'm2s1' and 'm2s2' as their interfaces are not distinguishable
interface g
subroutine m2s1(x)
end subroutine
subroutine m2s2(x)
real x
end subroutine
end interface
end
module m3
!ERROR: Generic 'g' may not have specific procedures 'm3f1' and 'm3f2' as their interfaces are not distinguishable
interface g
integer function m3f1()
end function
real function m3f2()
end function
end interface
end
module m4
type :: t1
end type
type, extends(t1) :: t2
end type
interface g
subroutine m4s1(x)
import :: t1
type(t1) :: x
end
subroutine m4s2(x)
import :: t2
type(t2) :: x
end
end interface
end
! These are all different ranks so they are distinguishable
module m5
interface g
subroutine m5s1(x)
real x
end subroutine
subroutine m5s2(x)
real x(:)
end subroutine
subroutine m5s3(x)
real x(:,:)
end subroutine
end interface
end
module m6
use m5
!ERROR: Generic 'g' may not have specific procedures 'm5s1' and 'm6s4' as their interfaces are not distinguishable
interface g
subroutine m6s4(x)
end subroutine
end interface
end
module m7
use m5
!ERROR: Generic 'g' may not have specific procedures 'm5s1' and 'm7s5' as their interfaces are not distinguishable
!ERROR: Generic 'g' may not have specific procedures 'm5s2' and 'm7s5' as their interfaces are not distinguishable
!ERROR: Generic 'g' may not have specific procedures 'm5s3' and 'm7s5' as their interfaces are not distinguishable
interface g
subroutine m7s5(x)
real x(..)
end subroutine
end interface
end
! Two procedures that differ only by attributes are not distinguishable
module m8
!ERROR: Generic 'g' may not have specific procedures 'm8s1' and 'm8s2' as their interfaces are not distinguishable
interface g
pure subroutine m8s1(x)
real, intent(in) :: x
end subroutine
subroutine m8s2(x)
real, intent(in) :: x
end subroutine
end interface
end
module m9
!ERROR: Generic 'g' may not have specific procedures 'm9s1' and 'm9s2' as their interfaces are not distinguishable
interface g
subroutine m9s1(x)
real :: x(10)
end subroutine
subroutine m9s2(x)
real :: x(100)
end subroutine
end interface
end
module m10
!ERROR: Generic 'g' may not have specific procedures 'm10s1' and 'm10s2' as their interfaces are not distinguishable
interface g
subroutine m10s1(x)
real :: x(10)
end subroutine
subroutine m10s2(x)
real :: x(..)
end subroutine
end interface
end
program m11
interface g1
subroutine m11s1(x)
real, pointer, intent(out) :: x
end subroutine
subroutine m11s2(x)
real, allocatable :: x
end subroutine
end interface
!ERROR: Generic 'g2' may not have specific procedures 'm11s3' and 'm11s4' as their interfaces are not distinguishable
interface g2
subroutine m11s3(x)
real, pointer, intent(in) :: x
end subroutine
subroutine m11s4(x)
real, allocatable :: x
end subroutine
end interface
end
module m12
!ERROR: Generic 'g1' may not have specific procedures 's1' and 's2' as their interfaces are not distinguishable
generic :: g1 => s1, s2 ! rank-1 and assumed-rank
!ERROR: Generic 'g2' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
generic :: g2 => s2, s3 ! scalar and assumed-rank
!ERROR: Generic 'g3' may not have specific procedures 's1' and 's4' as their interfaces are not distinguishable
generic :: g3 => s1, s4 ! different shape, same rank
contains
subroutine s1(x)
real :: x(10)
end
subroutine s2(x)
real :: x(..)
end
subroutine s3(x)
real :: x
end
subroutine s4(x)
real :: x(100)
end
end
! Procedures that are distinguishable by return type of a dummy argument
module m13
interface g1
procedure s1
procedure s2
end interface
interface g2
procedure s1
procedure s3
end interface
contains
subroutine s1(x)
procedure(real), pointer :: x
end
subroutine s2(x)
procedure(integer), pointer :: x
end
subroutine s3(x)
interface
function x()
procedure(real), pointer :: x
end function
end interface
end
end
! Check user-defined operators
module m14
interface operator(*)
module procedure f1
module procedure f2
end interface
!ERROR: Generic 'OPERATOR(+)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable
interface operator(+)
module procedure f1
module procedure f3
end interface
interface operator(.foo.)
module procedure f1
module procedure f2
end interface
!ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f1' and 'f3' as their interfaces are not distinguishable
interface operator(.bar.)
module procedure f1
module procedure f3
end interface
contains
real function f1(x, y)
real, intent(in) :: x
logical, intent(in) :: y
end
integer function f2(x, y)
integer, intent(in) :: x
logical, intent(in) :: y
end
real function f3(x, y)
real, value :: x
logical, value :: y
end
end module
! Types distinguished by kind (but not length) parameters
module m15
type :: t1(k1, l1)
integer, kind :: k1 = 1
integer, len :: l1 = 101
end type
type, extends(t1) :: t2(k2a, l2, k2b)
integer, kind :: k2a = 2
integer, kind :: k2b = 3
integer, len :: l2 = 102
end type
type, extends(t2) :: t3(l3, k3)
integer, kind :: k3 = 4
integer, len :: l3 = 103
end type
interface g1
procedure s1
procedure s2
end interface
!ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
interface g2
procedure s1
procedure s3
end interface
!ERROR: Generic 'g3' may not have specific procedures 's4' and 's5' as their interfaces are not distinguishable
interface g3
procedure s4
procedure s5
end interface
interface g4
procedure s5
procedure s6
procedure s9
end interface
interface g5
procedure s4
procedure s7
procedure s9
end interface
interface g6
procedure s5
procedure s8
procedure s9
end interface
!ERROR: Generic 'g7' may not have specific procedures 's6' and 's7' as their interfaces are not distinguishable
interface g7
procedure s6
procedure s7
end interface
!ERROR: Generic 'g8' may not have specific procedures 's6' and 's8' as their interfaces are not distinguishable
interface g8
procedure s6
procedure s8
end interface
!ERROR: Generic 'g9' may not have specific procedures 's7' and 's8' as their interfaces are not distinguishable
interface g9
procedure s7
procedure s8
end interface
contains
subroutine s1(x)
type(t1(1, 5)) :: x
end
subroutine s2(x)
type(t1(2, 4)) :: x
end
subroutine s3(x)
type(t1(l1=5)) :: x
end
subroutine s4(x)
type(t3(1, 101, 2, 102, 3, 103, 4)) :: x
end subroutine
subroutine s5(x)
type(t3) :: x
end subroutine
subroutine s6(x)
type(t3(1, 99, k2b=2, k2a=3, l2=*, l3=103, k3=4)) :: x
end subroutine
subroutine s7(x)
type(t3(k1=1, l1=99, k2a=3, k2b=2, k3=4)) :: x
end subroutine
subroutine s8(x)
type(t3(1, :, 3, :, 2, :, 4)), allocatable :: x
end subroutine
subroutine s9(x)
type(t3(k1=2)) :: x
end subroutine
end
! Check that specifics for type-bound generics can be distinguished
module m16
type :: t
contains
procedure, nopass :: s1
procedure, nopass :: s2
procedure, nopass :: s3
generic :: g1 => s1, s2
!ERROR: Generic 'g2' may not have specific procedures 's1' and 's3' as their interfaces are not distinguishable
generic :: g2 => s1, s3
end type
contains
subroutine s1(x)
real :: x
end
subroutine s2(x)
integer :: x
end
subroutine s3(x)
real :: x
end
end
! Check polymorphic types
module m17
type :: t
end type
type, extends(t) :: t1
end type
type, extends(t) :: t2
end type
type, extends(t2) :: t2a
end type
interface g1
procedure s1
procedure s2
end interface
!ERROR: Generic 'g2' may not have specific procedures 's3' and 's4' as their interfaces are not distinguishable
interface g2
procedure s3
procedure s4
end interface
interface g3
procedure s1
procedure s4
end interface
!ERROR: Generic 'g4' may not have specific procedures 's2' and 's3' as their interfaces are not distinguishable
interface g4
procedure s2
procedure s3
end interface
!ERROR: Generic 'g5' may not have specific procedures 's2' and 's5' as their interfaces are not distinguishable
interface g5
procedure s2
procedure s5
end interface
!ERROR: Generic 'g6' may not have specific procedures 's2' and 's6' as their interfaces are not distinguishable
interface g6
procedure s2
procedure s6
end interface
contains
subroutine s1(x)
type(t) :: x
end
subroutine s2(x)
type(t2a) :: x
end
subroutine s3(x)
class(t) :: x
end
subroutine s4(x)
class(t2) :: x
end
subroutine s5(x)
class(*) :: x
end
subroutine s6(x)
type(*) :: x
end
end
! Test C1514 rule 3 -- distinguishable passed-object dummy arguments
module m18
type :: t(k)
integer, kind :: k
contains
procedure, pass(x) :: p1 => s
procedure, pass :: p2 => s
procedure :: p3 => s
procedure, pass(y) :: p4 => s
generic :: g1 => p1, p4
generic :: g2 => p2, p4
generic :: g3 => p3, p4
end type
contains
subroutine s(x, y)
class(t(1)) :: x
class(t(2)) :: y
end
end
! C1511 - rules for operators
module m19
interface operator(.foo.)
module procedure f1
module procedure f2
end interface
!ERROR: Generic 'OPERATOR(.bar.)' may not have specific procedures 'f2' and 'f3' as their interfaces are not distinguishable
interface operator(.bar.)
module procedure f2
module procedure f3
end interface
contains
integer function f1(i)
integer, intent(in) :: i
end
integer function f2(i, j)
integer, value :: i, j
end
integer function f3(i, j)
integer, intent(in) :: i, j
end
end
module m20
interface operator(.not.)
real function m20f(x)
character(*),intent(in) :: x
end function
end interface
interface operator(+)
procedure m20f
end interface
end module
subroutine subr1()
use m20
interface operator(.not.)
!ERROR: Procedure 'm20f' from module 'm20' is already specified in generic 'OPERATOR(.NOT.)'
procedure m20f
end interface
interface operator(+)
!ERROR: Procedure 'm20f' from module 'm20' is already specified in generic 'OPERATOR(+)'
procedure m20f
end interface
end subroutine subr1
! Extensions for distinguishable allocatable arguments; these should not
! elicit errors from f18
module m21
type :: t
end type
interface int1
procedure s1a, s1b ! only one is polymorphic
end interface
interface int2
procedure s2a, s2b ! only one is unlimited polymorphic
end interface
contains
subroutine s1a(x)
type(t), allocatable :: x
end subroutine
subroutine s1b(x)
class(t), allocatable :: x
end subroutine
subroutine s2a(x)
class(t), allocatable :: x
end subroutine
subroutine s2b(x)
class(*), allocatable :: x
end subroutine
end module
|