4 ! Test the handling of optional, polymorphic and non-polymorphic arguments
5 ! to elemental procedures.
7 ! Original testcase by Tobias Burnus <burnus@net-b.de>
15 integer, allocatable :: a
16 integer, allocatable :: a2(:)
17 integer, pointer :: p => null()
18 integer, pointer :: p2(:) => null()
21 type(t), allocatable :: ta, taa(:)
22 type(t), pointer :: tp, tpa(:)
23 class(t), allocatable :: ca, caa(:)
24 class(t), pointer :: cp, cpa(:)
35 ! =============== sub1 ==================
36 ! SCALAR COMPONENTS: Non alloc/assoc
41 call sub1 (s, x%a, .false.)
42 call sub1 (v, x%a, .false.)
44 if (s /= 3) call abort()
45 if (any (v /= [9, 33])) call abort()
47 call sub1 (s, x%p, .false.)
48 call sub1 (v, x%p, .false.)
50 if (s /= 3) call abort()
51 if (any (v /= [9, 33])) call abort()
54 ! SCALAR COMPONENTS: alloc/assoc
59 call sub1 (s, x%a, .true.)
60 call sub1 (v, x%a, .true.)
62 if (s /= 4*2) call abort()
63 if (any (v /= [4*2, 4*2])) call abort()
65 call sub1 (s, x%p, .true.)
66 call sub1 (v, x%p, .true.)
68 if (s /= 5*2) call abort()
69 if (any (v /= [5*2, 5*2])) call abort()
72 ! ARRAY COMPONENTS: Non alloc/assoc
76 call sub1 (v, x%a2, .false.)
78 if (any (v /= [9, 33])) call abort()
80 call sub1 (v, x%p2, .false.)
82 if (any (v /= [9, 33])) call abort()
85 ! ARRAY COMPONENTS: alloc/assoc
87 allocate (x%a2(2), x%p2(2))
91 call sub1 (v, x%a2, .true.)
93 if (any (v /= [84*2, 82*2])) call abort()
95 call sub1 (v, x%p2, .true.)
97 if (any (v /= [35*2, 58*2])) call abort()
100 ! =============== sub_t ==================
101 ! SCALAR DT: Non alloc/assoc
106 call sub_t (s, ta, .false.)
107 call sub_t (v, ta, .false.)
109 if (s /= 3) call abort()
110 if (any (v /= [9, 33])) call abort()
112 call sub_t (s, tp, .false.)
113 call sub_t (v, tp, .false.)
115 if (s /= 3) call abort()
116 if (any (v /= [9, 33])) call abort()
118 call sub_t (s, ca, .false.)
119 call sub_t (v, ca, .false.)
121 if (s /= 3) call abort()
122 if (any (v /= [9, 33])) call abort()
124 call sub_t (s, cp, .false.)
125 call sub_t (v, cp, .false.)
127 if (s /= 3) call abort()
128 if (any (v /= [9, 33])) call abort()
130 ! SCALAR COMPONENTS: alloc/assoc
132 allocate (ta, tp, ca, cp)
138 call sub_t (s, ta, .true.)
139 call sub_t (v, ta, .true.)
141 if (s /= 4*2) call abort()
142 if (any (v /= [4*2, 4*2])) call abort()
144 call sub_t (s, tp, .true.)
145 call sub_t (v, tp, .true.)
147 if (s /= 5*2) call abort()
148 if (any (v /= [5*2, 5*2])) call abort()
150 call sub_t (s, ca, .true.)
151 call sub_t (v, ca, .true.)
153 if (s /= 6*2) call abort()
154 if (any (v /= [6*2, 6*2])) call abort()
156 call sub_t (s, cp, .true.)
157 call sub_t (v, cp, .true.)
159 if (s /= 7*2) call abort()
160 if (any (v /= [7*2, 7*2])) call abort()
162 ! ARRAY COMPONENTS: Non alloc/assoc
166 call sub_t (v, taa, .false.)
168 if (any (v /= [9, 33])) call abort()
170 call sub_t (v, tpa, .false.)
172 if (any (v /= [9, 33])) call abort()
174 call sub_t (v, caa, .false.)
176 if (any (v /= [9, 33])) call abort()
178 call sub_t (v, cpa, .false.)
180 if (any (v /= [9, 33])) call abort()
182 deallocate(ta, tp, ca, cp)
185 ! ARRAY COMPONENTS: alloc/assoc
187 allocate (taa(2), tpa(2))
188 taa(1:2)%a = [44, 444]
189 tpa(1:2)%a = [55, 555]
190 allocate (caa(2), source=[t(66), t(666)])
191 allocate (cpa(2), source=[t(77), t(777)])
195 if (any (caa(:)%a /= [66, 666])) call abort()
200 if (any (cpa(:)%a /= [77, 777])) call abort()
203 call sub_t (v, taa, .true.)
205 if (any (v /= [44*2, 444*2])) call abort()
207 call sub_t (v, tpa, .true.)
209 if (any (v /= [55*2, 555*2])) call abort()
212 call sub_t (v, caa, .true.)
214 if (any (v /= [66*2, 666*2])) call abort()
216 call sub_t (v, cpa, .true.)
218 if (any (v /= [77*2, 777*2])) call abort()
220 deallocate (taa, tpa, caa, cpa)
225 elemental subroutine sub1 (x, y, alloc)
226 integer, intent(inout) :: x
227 integer, intent(in), optional :: y
228 logical, intent(in) :: alloc
229 if (alloc .neqv. present (y)) &
235 elemental subroutine sub_t(x, y, alloc)
236 integer, intent(inout) :: x
237 type(t), intent(in), optional :: y
238 logical, intent(in) :: alloc
239 if (alloc .neqv. present (y)) &