2 ! Test the fix for PRs29396, 29606, 30625 and 30871, in which pointers
3 ! to arrays with subreferences did not work.
18 type(t
), pointer :: t(:)
21 integer, parameter :: sh(2) = (/2,2/)
22 real, parameter :: a1(2,2) = reshape ((/1.0,2.0,3.0,4.0/),sh
)
23 real, parameter :: a2(2,2) = reshape ((/5.0,6.0,7.0,8.0/),sh
)
25 type(t
), target
:: tar1(2) = (/t(1.0, 2, "abc"), t(3.0, 4, "efg")/)
26 character(4), target
:: tar2(2) = (/"abcd","efgh"/)
27 type(s
), target
:: tar3
28 character(2), target
:: tar4(2) = (/"ab","cd"/)
29 type(t2
), target
:: tar5(2) = (/t2(a1
, 2, "abc"), t2(a2
, 4, "efg")/)
31 integer, pointer :: ptr(:)
32 character(2), pointer :: ptr2(:)
33 real, pointer :: ptr3(:)
35 !_______________component subreference___________
37 ptr
= ptr
+ 1 ! check the scalarizer is OK
39 if (any (ptr
.ne
. (/3, 5/))) call abort ()
40 if (any ((/ptr(1), ptr(2)/) .ne
. (/3, 5/))) call abort ()
41 if (any (tar1
%i
.ne
. (/3, 5/))) call abort ()
43 ! Make sure that the other components are not touched.
44 if (any (tar1
%r
.ne
. (/1.0, 3.0/))) call abort ()
45 if (any (tar1
%chr
.ne
. (/"abc", "efg"/))) call abort ()
47 ! Check that the pointer is passed correctly as an actual argument.
49 if (any (tar1
%i
.ne
. (/2, 4/))) call abort ()
51 ! And that dummy pointers are OK too.
53 if (any (tar1
%i
.ne
. (/101, 103/))) call abort ()
55 !_______________substring subreference___________
57 ptr2
= ptr2(:)(2:2)//"z" ! again, check the scalarizer
59 if (any (ptr2
.ne
. (/"cz", "gz"/))) call abort ()
60 if (any ((/ptr2(1), ptr2(2)/) .ne
. (/"cz", "gz"/))) call abort ()
61 if (any (tar2
.ne
. (/"aczd", "egzh"/))) call abort ()
63 !_______________substring component subreference___________
64 ptr2
=> tar1(:)%chr(1:2)
65 ptr2
= ptr2(:)(2:2)//"q" ! yet again, check the scalarizer
66 if (any (ptr2
.ne
. (/"bq","fq"/))) call abort ()
67 if (any (tar1
%chr
.ne
. (/"bqc","fqg"/))) call abort ()
69 !_______________trailing array element subreference___________
71 ptr3
= (/99.0, 999.0/)
72 if (any (tar5(1)%r
.ne
. reshape ((/1.0,2.0,99.0,4.0/), sh
))) call abort ()
73 if (any (tar5(2)%r
.ne
. reshape ((/5.0,6.0,999.0,8.0/), sh
))) call abort ()
75 !_______________forall assignment___________
77 forall (i
= 1:2) ptr2(i
)(1:1) = "z"
78 if (any (tar2
.ne
. (/"zczd", "zgzh"/))) call abort ()
80 !_______________something more complicated___________
84 if (any (abs(ptr3
- (/cos(1.0_4
), cos(3.0_4
)/)) >= epsilon(1.0_4
))) call abort ()
86 ptr2
=> tar3
%t(:)%chr(2:3)
88 if (any (tar1
%chr
.ne
. (/"b x", "f x"/))) call abort ()
90 !_______________check non-subref works still___________
92 if (any (ptr2
.ne
. (/"ab","cd"/))) call abort ()
100 integer, pointer :: arg(:)