3 ! In the course of fixing PR83118, lots of issues came up with class array
4 ! assignment, where temporaries are generated. This testcase checks that
5 ! it all works correctly.
7 ! Contributed by Paul Thomas <pault@gcc.gnu.org>
15 type, extends(t1
) :: t2
20 module procedure add_t1
24 function add_t1 (a
, b
) result (c
)
25 class(t1
), intent(in
) :: a(:), b(:)
26 class(t1
), allocatable
:: c(:)
27 allocate (c
, source
= a
)
44 class(t1
), dimension(:), allocatable
:: x
, y
46 x
= [t2(1,10.0),t2(2,20.0),t2(3,30.0)]
47 if (.not
.check_t1 (x
, [1,2,3], 2, [10, 20, 30]) ) stop 1
51 if (.not
.check_t1 (x
, [3,2,1], 1) ) stop 2
54 if (.not
.check_t1 (x
, [2,3,1], 1) ) stop 3
57 if (.not
.check_t1 (x
, [1,2,3], 1) ) stop 4
60 if (.not
.check_t1 (x
, [4,4,4], 1) ) stop 5
63 if (.not
.check_t1 (x
, [5,6,7], 2) ) stop 6
65 ! Now check that the dynamic type survives assignments.
66 x
= [t2(1,10.0),t2(2,20.0),t2(3,30.0)]
70 if (.not
.check_t1 (x
, [3,2,1], 2, [30,20,10]) ) stop 7
73 if (.not
.check_t1 (x
, [2,4,6], 2, [20,40,60]) ) stop 8
76 if (.not
.check_t1 (x
, [6,4,2], 2, [60,40,20]) ) stop 9
79 if (.not
.check_t1 (x
, [2,4,6], 2, [20,40,60]) ) stop 10
83 function realloc_t1 (arg
) result (res
)
84 class(t1
), dimension(:), allocatable
:: arg
85 class(t1
), dimension(:), allocatable
:: res
88 allocate (res
, source
= [t1 (arg(3)%i
), t1 (arg(2)%i
), t1 (arg(1)%i
)])
90 allocate (res
, source
= [t1 (arg(2)%i
), t1 (arg(1)%i
), t1 (arg(3)%i
)])
92 end function realloc_t1
94 logical function check_t1 (arg
, array
, t
, array2
)
96 integer :: array (:), t
97 integer, optional
:: array2(:)
101 if (any (arg
%i
.ne
. array
)) check_t1
= .false
.
102 if (t
.eq
. 2) check_t1
= .false
.
104 if (any (arg
%i
.ne
. array
)) check_t1
= .false
.
105 if (t
.eq
. 1) check_t1
= .false
.
106 if (present (array2
)) then
107 if (any(int (arg
%r
) .ne
. array2
)) check_t1
= .false
.
112 end function check_t1
114 end subroutine test_t1
120 class(*), dimension(:), allocatable
:: x
, y
122 x
= [t2(1,10.0),t2(2,20.0),t2(3,30.0)]
123 if (.not
.check_star (x
, [1,2,3], 2) ) stop 11
127 if (.not
.check_star (x
, [3,2,1], 1) ) stop 12
130 if (.not
.check_star (x
, [2,3,1], 1) ) stop 13
133 if (.not
.check_star (x
, [1,2,3], 1) ) stop 14
136 if (.not
.check_star (x
, [3,2,1], 1) ) stop 15
138 ! Make sure that all is similarly well with type t2.
139 x
= [t2(1,10.0),t2(2,20.0),t2(3,30.0)]
142 if (.not
.check_star (x
, [3,1,2], 2, [30,10,20]) ) stop 16
145 if (.not
.check_star (x
, [2,1,3], 2, [20,10,30]) ) stop 17
149 function realloc_star (arg
) result (res
)
150 class(*), dimension(:), allocatable
:: arg
151 class(*), dimension(:), allocatable
:: res
154 allocate (res
, source
= [t1 (arg(3)%i
), t1 (arg(2)%i
), t1 (arg(1)%i
)])
156 allocate (res
, source
= [t1 (arg(2)%i
), t1 (arg(1)%i
), t1 (arg(3)%i
)])
158 end function realloc_star
160 logical function check_star (arg
, array
, t
, array2
)
162 integer :: array (:), t
163 integer, optional
:: array2(:)
167 if (any (arg
%i
.ne
. array
)) check_star
= .false
.
168 if (t
.eq
. 2) check_star
= .false
.
170 if (any (arg
%i
.ne
. array
)) check_star
= .false
.
171 if (t
.eq
. 1) check_star
= .false
.
172 if (present (array2
)) then
173 if (any (int(arg
%r
) .ne
. array2
)) check_star
= .false
.
178 end function check_star
180 end subroutine test_star