5 ! Check that passing a CLASS function result to a derived TYPE works
7 ! Reported by Tobias Burnus <burnus@gcc.gnu.org>
19 real, allocatable
:: rr(:)
22 real, allocatable
:: rrr(:)
28 x
= func1() ! scalar to scalar - no alloc comps
29 if (x
%ii
.ne
. 77) STOP 1
31 y
= func2() ! array to array - no alloc comps
32 if (any (y
%ii
.ne
. [1,2,3])) STOP 2
34 y
= func1() ! scalar to array - no alloc comps
35 if (any (y
%ii
.ne
. 77)) STOP 3
37 x
= func3() ! scalar daughter type to scalar - no alloc comps
38 if (x
%ii
.ne
. 99) STOP 4
40 y
= func4() ! array daughter type to array - no alloc comps
41 if (any (y
%ii
.ne
. [3,4,5])) STOP 5
43 y
= func3() ! scalar daughter type to array - no alloc comps
44 if (any (y
%ii
.ne
. [99,99,99])) STOP 6
46 a
= func5() ! scalar to scalar - alloc comps in parent type
47 if (any (a
%rr
.ne
. [10.0,20.0])) STOP 7
49 b
= func6() ! array to array - alloc comps in parent type
50 if (any (b(3)%rr
.ne
. [3.0,4.0])) STOP 8
52 a
= func7() ! scalar daughter type to scalar - alloc comps in parent type
53 if (any (a
%rr
.ne
. [10.0,20.0])) STOP 9
55 b
= func8() ! array daughter type to array - alloc comps in parent type
56 if (any (b(3)%rr
.ne
. [3.0,4.0])) STOP 10
58 b
= func7() ! scalar daughter type to array - alloc comps in parent type
59 if (any (b(2)%rr
.ne
. [10.0,20.0])) STOP 11
61 ! This is an extension of class_to_type_2.f90's test using a daughter type
62 ! instead of the declared type.
63 if (subpr2_array (g ()) .ne
. 99 ) STOP 12
66 function func1() result(res
)
67 class(t
), allocatable
:: res
68 allocate (res
, source
= t(77))
71 function func2() result(res
)
72 class(t
), allocatable
:: res(:)
73 allocate (res(3), source
= [u(1,1.0),u(2,2.0),u(3,3.0)])
76 function func3() result(res
)
77 class(t
), allocatable
:: res
78 allocate (res
, source
= v(99,[99.0,99.0,99.0]))
81 function func4() result(res
)
82 class(t
), allocatable
:: res(:)
83 allocate (res(3), source
= [v(3,[1.0,2.0]),v(4,[2.0,3.0]),v(5,[3.0,4.0])])
86 function func5() result(res
)
87 class(v
), allocatable
:: res
88 allocate (res
, source
= v(3,[10.0,20.0]))
91 function func6() result(res
)
92 class(v
), allocatable
:: res(:)
93 allocate (res(3), source
= [v(3,[1.0,2.0]),v(4,[2.0,3.0]),v(5,[3.0,4.0])])
96 function func7() result(res
)
97 class(v
), allocatable
:: res
98 allocate (res
, source
= w(3,[10.0,20.0],[100,200]))
101 function func8() result(res
)
102 class(v
), allocatable
:: res(:)
103 allocate (res(3), source
= [w(3,[1.0,2.0],[0.0]),w(4,[2.0,3.0],[0.0]),w(5,[3.0,4.0],[0.0])])
107 integer function subpr2_array (x
)
109 if (any(x(:)%ii
/= 55)) STOP 13
113 function g () result(res
)
115 class(t
), allocatable
:: res(:)
116 allocate (res(3), source
= [(v (1, [1.0,2.0]), i
= 1, 3)])