Debian Codegraph @

gcc/testsuite/gfortran.dg/derived_result_3.f90

raw
1 ! { dg-do run }
2 ! PR fortran/98454 - default-initialization of derived-type function results
3
4 program test
5 implicit none
6 type t
7 integer :: unit = -1
8 end type t
9 type u
10 integer, allocatable :: unit(:)
11 end type u
12 type(t) :: x, x3(3)
13 type(u) :: y, y4(4)
14
15 ! Scalar function result, DT with default initializer
16 x = t(42)
17 if (x% unit /= 42) stop 1
18 x = g()
19 if (x% unit /= -1) stop 2
20 x = t(42)
21 x = f()
22 if (x% unit /= -1) stop 3
23 x = t(42)
24 x = h()
25 if (x% unit /= -1) stop 4
26 x = t(42)
27 x = k()
28 if (x% unit /= -1) stop 5
29
30 ! Array function result, DT with default initializer
31 x3 = t(13)
32 if (any (x3% unit /= 13)) stop 11
33 x3 = f3()
34 if (any (x3% unit /= -1)) stop 12
35 x3 = t(13)
36 x3 = g3()
37 if (any (x3% unit /= -1)) stop 13
38 x3 = t(13)
39 x3 = h3()
40 if (any (x3% unit /= -1)) stop 14
41 x3 = t(13)
42 x3 = k3()
43 if (any (x3% unit /= -1)) stop 15
44
45 ! Scalar function result, DT with allocatable component
46 y = u()
47 if (allocated (y% unit)) stop 21
48 allocate (y% unit(42))
49 y = m()
50 if (allocated (y% unit)) stop 22
51 allocate (y% unit(42))
52 y = n()
53 if (allocated (y% unit)) stop 23
54 allocate (y% unit(42))
55 y = o()
56 if (allocated (y% unit)) stop 24
57 allocate (y% unit(42))
58 y = p()
59 if (allocated (y% unit)) stop 25
60
61 ! Array function result, DT with allocatable component
62 y4 = u()
63 if (allocated (y4(1)% unit)) stop 31
64 allocate (y4(1)% unit(42))
65 y4 = m4()
66 if (allocated (y4(1)% unit)) stop 32
67 y4 = u()
68 allocate (y4(1)% unit(42))
69 y4 = n4()
70 if (allocated (y4(1)% unit)) stop 33
71
72 y4 = u()
73 allocate (y4(1)% unit(42))
74 y4 = o4()
75 if (allocated (y4(1)% unit)) stop 34
76 y4 = u()
77 allocate (y4(1)% unit(42))
78 y4 = p4()
79 if (allocated (y4(1)% unit)) stop 35
80
81 contains
82
83 ! Function result not referenced within function body
84 function f()
85 type(t) :: f
86 end function f
87
88 function k() result (f)
89 type(t) :: f
90 end function k
91
92 ! Function result referenced within function body
93 function g()
94 type(t) :: g
95 if (g% unit /= -1) stop 41
96 end function g
97
98 function h() result (g)
99 type(t) :: g
100 if (g% unit /= -1) stop 42
101 end function h
102
103 ! Function result not referenced within function body
104 function f3 ()
105 type(t) :: f3(3)
106 end function f3
107
108 function k3() result (f3)
109 type(t) :: f3(3)
110 end function k3
111
112 ! Function result referenced within function body
113 function g3()
114 type(t) :: g3(3)
115 if (any (g3% unit /= -1)) stop 43
116 end function g3
117
118 function h3() result (g3)
119 type(t) :: g3(3)
120 if (any (g3% unit /= -1)) stop 44
121 end function h3
122
123 function m()
124 type(u) :: m
125 end function m
126
127 function n() result (f)
128 type(u) :: f
129 end function n
130
131 function o()
132 type(u) :: o
133 if (allocated (o% unit)) stop 71
134 end function o
135
136 function p() result (f)
137 type(u) :: f
138 if (allocated (f% unit)) stop 72
139 end function p
140
141 function m4()
142 type(u) :: m4(4)
143 end function m4
144
145 function n4() result (f)
146 type(u) :: f(4)
147 end function n4
148
149 function o4()
150 type(u) :: o4(4)
151 if (allocated (o4(1)% unit)) stop 73
152 end function o4
153
154 function p4() result (f)
155 type(u) :: f(4)
156 if (allocated (f(1)% unit)) stop 74
157 end function p4
158 end