| 1 |
! { dg-do compile } |
| 2 |
! PR fortran/58331 - rank checking for CLASS dummy arguments |
| 3 |
|
| 4 |
module mymod |
| 5 |
implicit none |
| 6 |
contains |
| 7 |
subroutine mysub(a, n) |
| 8 |
integer, intent(in) :: n |
| 9 |
class(*), intent(in) :: a(n) |
| 10 |
|
| 11 |
select type(a) |
| 12 |
type is(integer) |
| 13 |
print *,'a is integer' |
| 14 |
print *, "n=", n, ' a=', a |
| 15 |
class default |
| 16 |
print *,'a is unsupported type' |
| 17 |
stop 1 |
| 18 |
end select |
| 19 |
end |
| 20 |
|
| 21 |
! Assumed rank |
| 22 |
subroutine sub_ar (a) |
| 23 |
class(*), intent(in) :: a(..) |
| 24 |
print *, rank (a), size (a), ":", shape (a) |
| 25 |
end |
| 26 |
|
| 27 |
! Assumed shape |
| 28 |
subroutine sub_as1 (a) |
| 29 |
class(*), intent(in) :: a(:) |
| 30 |
print *, rank (a), size (a), ":", shape (a) |
| 31 |
end |
| 32 |
subroutine sub_as2 (b) |
| 33 |
class(*), intent(in) :: b(:,:) |
| 34 |
print *, rank (b), size (b), ":", shape (b) |
| 35 |
end |
| 36 |
end |
| 37 |
|
| 38 |
program p |
| 39 |
use mymod |
| 40 |
implicit none |
| 41 |
integer :: a(3) = [11, 12, 13] |
| 42 |
integer :: b(2,2) = reshape([21, 22, 23, 24], [2,2]) |
| 43 |
integer :: c = 1 |
| 44 |
|
| 45 |
call mysub(a,3) |
| 46 |
call mysub(b,4) |
| 47 |
call sub_ar(a) |
| 48 |
call sub_ar(b) |
| 49 |
call sub_ar(c) |
| 50 |
call sub_as1(a) |
| 51 |
call sub_as2(b) |
| 52 |
! |
| 53 |
call mysub(c,1) ! { dg-error "rank-1 and scalar" } |
| 54 |
call sub_as1(b) ! { dg-error "rank-1 and rank-2" } |
| 55 |
call sub_as2(a) ! { dg-error "rank-2 and rank-1" } |
| 56 |
end |