2 ! { dg-options "-fcheck=all" }
6 ! Assumed-rank tests - same as assumed_rank_1.f90,
7 ! but with bounds checks and w/o call to C function
12 integer, target
:: x(2:5,4:7), y(-4:4)
13 integer, allocatable
, target
:: z(:,:,:,:)
14 integer, allocatable
:: val(:)
17 allocate(z(1:4, -2:5, 4, 10:11))
19 if (rank(x
) /= 2) call abort ()
20 val
= [(2*i
+3, i
= 1, size(x
))]
21 x
= reshape (val
, shape(x
))
22 call foo(x
, rank(x
), lbound(x
), ubound(x
), val
)
23 call foo2(x
, rank(x
), lbound(x
), ubound(x
), val
)
25 call bar(x
,prsnt
=.false
.)
27 if (rank(y
) /= 1) call abort ()
28 val
= [(2*i
+7, i
= 1, size(y
))]
29 y
= reshape (val
, shape(y
))
30 call foo(y
, rank(y
), lbound(y
), ubound(y
), val
)
31 call foo2(y
, rank(y
), lbound(y
), ubound(y
), val
)
33 call bar(y
,prsnt
=.false
.)
35 if (rank(z
) /= 4) call abort ()
36 val
= [(2*i
+5, i
= 1, size(z
))]
37 z(:,:,:,:) = reshape (val
, shape(z
))
38 call foo(z
, rank(z
), lbound(z
), ubound(z
), val
)
39 call foo(z
, rank(z
), lbound(z
), ubound(z
), val
)
40 call foo2(z
, rank(z
), lbound(z
), ubound(z
), val
)
42 call bar(z
,prsnt
=.false
.)
45 subroutine bar(a
,b
, prsnt
)
46 integer, pointer, optional
, intent(in
) :: a(..),b(..)
47 logical, value
:: prsnt
48 if (.not
. associated(a
)) call abort()
50 ! The following is not valid
51 ! Technically, it could be allowed and might be in Fortran 2015:
52 ! if (.not. associated(a,b)) call abort()
54 if (.not
. associated(a
)) call abort()
56 if (.not
. present(a
)) call abort()
57 if (prsnt
.neqv
. present(b
)) call abort()
60 ! POINTER argument - bounds as specified before
61 subroutine foo(a
, rnk
, low
, high
, val
)
62 integer,pointer, intent(in
) :: a(..)
64 integer, intent(in
) :: low(:), high(:), val(:)
69 if (rank(a
) /= rnk
) call abort()
70 if (size(low
) /= rnk
.or
. size(high
) /= rnk
) call abort()
71 if (size(a
) /= product (high
- low
+1)) call abort()
74 if (low(1) /= lbound(a
,1)) call abort()
75 if (high(1) /= ubound(a
,1)) call abort()
76 if (size (a
,1) /= high(1)-low(1)+1) call abort()
80 if (low(i
) /= lbound(a
,i
)) call abort()
81 if (high(i
) /= ubound(a
,i
)) call abort()
82 if (size (a
,i
) /= high(i
)-low(i
)+1) call abort()
84 call foo2(a
, rnk
, low
, high
, val
)
87 ! Non-pointer, non-allocatable bounds. lbound == 1
88 subroutine foo2(a
, rnk
, low
, high
, val
)
89 integer, intent(in
) :: a(..)
91 integer, intent(in
) :: low(:), high(:), val(:)
94 if (rank(a
) /= rnk
) call abort()
95 if (size(low
) /= rnk
.or
. size(high
) /= rnk
) call abort()
96 if (size(a
) /= product (high
- low
+1)) call abort()
99 if (1 /= lbound(a
,1)) call abort()
100 if (high(1)-low(1)+1 /= ubound(a
,1)) call abort()
101 if (size (a
,1) /= high(1)-low(1)+1) call abort()
105 if (1 /= lbound(a
,i
)) call abort()
106 if (high(i
)-low(i
)+1 /= ubound(a
,i
)) call abort()
107 if (size (a
,i
) /= high(i
)-low(i
)+1) call abort()
111 ! ALLOCATABLE argument - bounds as specified before
112 subroutine foo3 (a
, rnk
, low
, high
, val
)
113 integer, allocatable
, intent(in
), target
:: a(..)
114 integer, value
:: rnk
115 integer, intent(in
) :: low(:), high(:), val(:)
118 if (rank(a
) /= rnk
) call abort()
119 if (size(low
) /= rnk
.or
. size(high
) /= rnk
) call abort()
120 if (size(a
) /= product (high
- low
+1)) call abort()
123 if (low(1) /= lbound(a
,1)) call abort()
124 if (high(1) /= ubound(a
,1)) call abort()
125 if (size (a
,1) /= high(1)-low(1)+1) call abort()
129 if (low(i
) /= lbound(a
,i
)) call abort()
130 if (high(i
) /= ubound(a
,i
)) call abort()
131 if (size (a
,i
) /= high(i
)-low(i
)+1) call abort()
133 call foo(a
, rnk
, low
, high
, val
)