| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! TS 29113 |
| 4 |
! 6.4.3 UBOUND |
| 5 |
! |
| 6 |
! The description of the intrinsic function UBOUND in ISO/IEC |
| 7 |
! 1539-1:2010 is changed for an assumed-rank object that is associated |
| 8 |
! with an assumed-size array; the result of UBOUND (ARRAY, RANK(ARRAY), |
| 9 |
! KIND) has a value equal to LBOUND (ARRAY, RANK (ARRAY), KIND) −2 with |
| 10 |
! KIND omitted from LBOUND if it was omitted from UBOUND. |
| 11 |
! |
| 12 |
! NOTE 6.2 |
| 13 |
! If LBOUND or UBOUND is invoked for an assumed-rank object that is |
| 14 |
! associated with a scalar and DIM is absent, the result is a zero-sized |
| 15 |
! array. LBOUND or UBOUND cannot be invoked for an assumed-rank object |
| 16 |
! that is associated with a scalar if DIM is present because the rank of |
| 17 |
! a scalar is zero and DIM must be ≥ 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 testit2(x1, shape(x1)) |
| 39 |
call test1 (y1) |
| 40 |
call testit2(y1, shape(y1)) |
| 41 |
p1 => x1 |
| 42 |
call testit2(p1, shape(p1)) |
| 43 |
call testit2p(p1, lbound(p1), shape(p1)) |
| 44 |
call test1 (p1) |
| 45 |
p1(77:) => x1 |
| 46 |
call testit2p(p1, [77], shape(p1)) |
| 47 |
allocate (a1(5)) |
| 48 |
call testit2(a1, shape(a1)) |
| 49 |
call testit2a(a1, lbound(a1), shape(a1)) |
| 50 |
call test1 (a1) |
| 51 |
deallocate(a1) |
| 52 |
allocate (a1(-38:5)) |
| 53 |
call test1 (a1) |
| 54 |
call testit2(a1, shape(a1)) |
| 55 |
call testit2a(a1, [-38], shape(a1)) |
| 56 |
|
| 57 |
! Test the multi-dimensional arrays. |
| 58 |
call test3 (x3, 1, 2, 1, 3) |
| 59 |
call test3 (y3, 0, 1, -3, -1) |
| 60 |
p3 => x3 |
| 61 |
call test3 (p3, 1, 2, 1, 3) |
| 62 |
allocate (a3(2,3,4)) |
| 63 |
call test3 (a3, 1, 2, 1, 3) |
| 64 |
|
| 65 |
! Test some scalars. |
| 66 |
call test0 (x) |
| 67 |
call test0 (-1) |
| 68 |
call test0 (x1(1)) |
| 69 |
|
| 70 |
contains |
| 71 |
|
| 72 |
subroutine testit (a) |
| 73 |
integer :: a(..) |
| 74 |
integer :: r |
| 75 |
r = rank(a) |
| 76 |
if (any (lbound (a) .ne. 1)) stop 101 |
| 77 |
if (ubound (a, r) .ne. -1) stop 102 |
| 78 |
end subroutine |
| 79 |
|
| 80 |
subroutine testit2(a, shape) |
| 81 |
integer :: a(..) |
| 82 |
integer :: shape(:) |
| 83 |
if (rank(a) /= size(shape)) stop 111 |
| 84 |
if (any (lbound(a) /= 1)) stop 112 |
| 85 |
if (any (ubound(a) /= shape)) stop 113 |
| 86 |
end subroutine |
| 87 |
|
| 88 |
subroutine testit2a(a,lbound2, shape2) |
| 89 |
integer, allocatable :: a(..) |
| 90 |
integer :: lbound2(:), shape2(:) |
| 91 |
if (rank(a) /= size(shape2)) stop 121 |
| 92 |
if (any (lbound(a) /= lbound2)) stop 122 |
| 93 |
if (any (ubound(a) /= lbound2 + shape2 - 1)) stop 123 |
| 94 |
if (any (shape(a) /= shape2)) stop 124 |
| 95 |
if (sum (shape(a)) /= size(a)) stop 125 |
| 96 |
end subroutine |
| 97 |
|
| 98 |
subroutine testit2p(a, lbound2, shape2) |
| 99 |
integer, pointer :: a(..) |
| 100 |
integer :: lbound2(:), shape2(:) |
| 101 |
if (rank(a) /= size(shape2)) stop 131 |
| 102 |
if (any (lbound(a) /= lbound2)) stop 132 |
| 103 |
if (any (ubound(a) /= lbound2 + shape2 - 1)) stop 133 |
| 104 |
if (any (shape(a) /= shape2)) stop 134 |
| 105 |
if (sum (shape(a)) /= size(a)) stop 135 |
| 106 |
end subroutine |
| 107 |
|
| 108 |
subroutine test0 (a) |
| 109 |
integer :: a(..) |
| 110 |
if (rank (a) .ne. 0) stop 141 |
| 111 |
if (size (lbound (a)) .ne. 0) stop 142 |
| 112 |
if (size (ubound (a)) .ne. 0) stop 143 |
| 113 |
end subroutine |
| 114 |
|
| 115 |
subroutine test1 (a) |
| 116 |
integer :: a(*) |
| 117 |
|
| 118 |
call testit (a) |
| 119 |
end subroutine |
| 120 |
|
| 121 |
subroutine test3 (a, l1, u1, l2, u2) |
| 122 |
implicit none |
| 123 |
integer :: l1, u1, l2, u2 |
| 124 |
integer :: a(l1:u1, l2:u2, *) |
| 125 |
|
| 126 |
call testit (a) |
| 127 |
end subroutine |
| 128 |
|
| 129 |
end program |