5 implicit none (type, external)
6 real, target
:: AT(10,10), BT
7 real, contiguous
, pointer :: A(:,:)
9 real, pointer :: AP(:,:), BP
10 real, pointer :: CP(:), DP(:,:), D
, EP(:)
19 call foo(AP
,B
, A
, 1) ! OK - associated
20 call foo(BP
,B
, A
, 2) ! OK - associated
22 ! Those are all not associated:
26 call foo(AP
, B
, A
, 3) ! LHS not associated
27 call foo(BP
, B
, A
, 4) ! LHS not associated
31 call foo(AP
, B
, DP
, 5) ! LHS+RHS not associated
32 call foo(BP
, D
, A
, 6) ! LHS+RHS not associated
36 call foo(AP
, B
, DP
, 7) ! RHS not associated
37 call foo(BP
, D
, A
, 8) ! RHS not associated
40 call foo(CP
, B
, A
, 9) ! Shape (rank) differs
43 call foo(AP
, B
, A
, 10) ! Shape differs
46 call foo(AP
, B
, A
, 11) ! Shape differs
49 call foo(AP
, B
, A
, 12) ! OK - bounds different, shape same
52 EP
=> AT(1:-1, 5) ! Case(i) + case(iv)
53 call foo2(CP
, EP
) ! CP associated - but CP not associated with EP
55 subroutine foo2(p
, lpd
)
56 implicit none (type, external)
57 real, pointer :: p(..) ! "pointer"
58 real, pointer :: lpd(:) ! array "target"
59 if (.not
.associated(p
)) stop 18 ! OK - associated
60 if (associated(p
, lpd
)) stop 19 ! .. but for zero-sized array
63 subroutine foo(p
, lp
, lpd
, cnt
)
64 implicit none (type, external)
65 real, pointer :: p(..) ! "pointer"
66 real, pointer :: lp
! scalar "target"
67 real, pointer :: lpd(:,:) ! array "target"
71 if (.not
. associated(p
, lpd
)) stop 1 ! OK
72 elseif (cnt
== 2) then
73 if (.not
. associated(p
, lp
)) stop 2 ! OK
74 elseif (cnt
== 3) then
75 if (associated(p
, lpd
)) stop 3 ! LHS NULL ptr
76 if (associated(p
)) stop 4 ! LHS NULL ptr
77 elseif (cnt
== 4) then
78 if (associated(p
, lp
)) stop 5 ! LHS NULL ptr
79 if (associated(p
)) stop 6 ! LHS NULL ptr
80 elseif (cnt
== 5) then
81 if (associated(p
, lpd
)) stop 7 ! LHS+RHS NULL ptr
82 if (associated(p
)) stop 8 ! LHS+RHS NULL ptr
83 elseif (cnt
== 6) then
84 if (associated(p
, lp
)) stop 9 ! LHS+RHS NULL ptr
85 if (associated(p
)) stop 10 ! LHS+RHS NULL ptr
86 elseif (cnt
== 7) then
87 if (associated(p
, lpd
)) stop 11 ! RHS NULL ptr
88 elseif (cnt
== 8) then
89 if (associated(p
, lp
)) stop 12 ! RHS NULL ptr
90 elseif (cnt
== 9) then
91 if (associated(p
, lpd
)) stop 13 ! rank differs
92 if (associated(p
, lp
)) stop 14 ! rank differs
93 elseif (cnt
== 10) then
94 if (associated(p
, lpd
)) stop 15 ! shape differs
95 elseif (cnt
== 11) then
96 if (associated(p
, lpd
)) stop 16 ! shape differs
97 elseif (cnt
== 12) then
98 if (.not
.associated(p
, lpd
)) stop 17 ! OK - shape same, lbound different
103 subroutine test_char()
104 character(len
=0), target
:: str0
105 character(len
=2), target
:: str2
106 character(len
=:), pointer :: ptr
108 call test_char2(ptr
, str0
)
110 call test_char2(ptr
, str2
)
112 subroutine test_char2(x
,y
)
113 character(len
=:), pointer :: x
114 character(len
=*), target
:: y
115 if (len(y
) == 0) then
116 if (len(x
) /= 0) stop 20
117 if (.not
. associated(x
)) stop 21
118 if (associated(x
, y
)) stop 22
120 if (len(y
) /= 2) stop 23
121 if (len(x
) /= 2) stop 24
122 if (.not
. associated(x
)) stop 25
123 if (.not
. associated(x
, y
)) stop 26