| 1 |
! Reported as pr94070. |
| 2 |
! { dg-do run } |
| 3 |
! |
| 4 |
! TS 29113 |
| 5 |
! 6.4.2 SIZE |
| 6 |
! |
| 7 |
! The description of the intrinsic function SIZE in ISO/IEC 1539-1:2010 |
| 8 |
! is changed in the following cases: |
| 9 |
! |
| 10 |
! (1) for an assumed-rank object that is associated with an assumed-size |
| 11 |
! array, the result has the value −1 if DIM is present and equal to the |
| 12 |
! rank of ARRAY, and a negative value that is equal to |
| 13 |
! PRODUCT ( [ (SIZE (ARRAY, I, KIND), I=1, RANK (ARRAY)) ] ) |
| 14 |
! if DIM is not present; |
| 15 |
! |
| 16 |
! (2) for an assumed-rank object that is associated with a scalar, the |
| 17 |
! result has the value 1. |
| 18 |
! |
| 19 |
! The idea here is that the main program passes some arrays to a test |
| 20 |
! subroutine with an assumed-size dummy, which in turn passes that to a |
| 21 |
! subroutine with an assumed-rank dummy. |
| 22 |
|
| 23 |
program test |
| 24 |
|
| 25 |
! Define some arrays for testing. |
| 26 |
integer, target :: x1(5) |
| 27 |
integer :: y1(0:9) |
| 28 |
integer, pointer :: p1(:) |
| 29 |
integer, allocatable :: a1(:) |
| 30 |
integer, target :: x3(2,3,4) |
| 31 |
integer :: y3(0:1,-3:-1,4) |
| 32 |
integer, pointer :: p3(:,:,:) |
| 33 |
integer, allocatable :: a3(:,:,:) |
| 34 |
integer :: x |
| 35 |
|
| 36 |
! Test the 1-dimensional arrays. |
| 37 |
call test1 (x1) |
| 38 |
call test1 (y1) |
| 39 |
p1 => x1 |
| 40 |
call test1 (p1) |
| 41 |
allocate (a1(5)) |
| 42 |
call test1 (a1) |
| 43 |
|
| 44 |
! Test the multi-dimensional arrays. |
| 45 |
call test3 (x3, 1, 2, 1, 3) |
| 46 |
call test3 (y3, 0, 1, -3, -1) |
| 47 |
p3 => x3 |
| 48 |
call test3 (p3, 1, 2, 1, 3) |
| 49 |
allocate (a3(2,3,4)) |
| 50 |
call test3 (a3, 1, 2, 1, 3) |
| 51 |
|
| 52 |
! Test scalars. |
| 53 |
call test0 (x) |
| 54 |
call test0 (-1) |
| 55 |
call test0 (x1(1)) |
| 56 |
|
| 57 |
contains |
| 58 |
|
| 59 |
subroutine testit (a, r, sizes) |
| 60 |
integer :: a(..) |
| 61 |
integer :: r |
| 62 |
integer :: sizes(r) |
| 63 |
|
| 64 |
integer :: totalsize, thissize |
| 65 |
totalsize = 1 |
| 66 |
|
| 67 |
if (r .ne. rank(a)) stop 101 |
| 68 |
|
| 69 |
do i = 1, r |
| 70 |
thissize = size (a, i) |
| 71 |
print *, 'got size ', thissize, ' expected ', sizes(i) |
| 72 |
if (thissize .ne. sizes(i)) stop 102 |
| 73 |
totalsize = totalsize * thissize |
| 74 |
end do |
| 75 |
|
| 76 |
if (size(a) .ne. totalsize) stop 103 |
| 77 |
end subroutine |
| 78 |
|
| 79 |
subroutine test0 (a) |
| 80 |
integer :: a(..) |
| 81 |
|
| 82 |
if (size (a) .ne. 1) stop 103 |
| 83 |
end subroutine |
| 84 |
|
| 85 |
subroutine test1 (a) |
| 86 |
integer :: a(*) |
| 87 |
|
| 88 |
integer :: sizes(1) |
| 89 |
sizes(1) = -1 |
| 90 |
call testit (a, 1, sizes) |
| 91 |
end subroutine |
| 92 |
|
| 93 |
subroutine test3 (a, l1, u1, l2, u2) |
| 94 |
implicit none |
| 95 |
integer :: l1, u1, l2, u2 |
| 96 |
integer :: a(l1:u1, l2:u2, *) |
| 97 |
|
| 98 |
integer :: sizes(3) |
| 99 |
sizes(1) = u1 - l1 + 1 |
| 100 |
sizes(2) = u2 - l2 + 1 |
| 101 |
sizes(3) = -1 |
| 102 |
|
| 103 |
call testit (a, 3, sizes) |
| 104 |
end subroutine |
| 105 |
|
| 106 |
end program |