3 ! Automatic reallocate on assignment, deferred length parameter for char
9 ! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
21 subroutine source_check()
22 character(len=:), allocatable :: str, str2
24 character(len=8) :: str3
25 character(len=:), pointer :: str4, str5
28 if(allocated(str)) call abort()
29 allocate(str, source=str3)
30 if(.not.allocated(str)) call abort()
31 if(len(str) /= 8) call abort()
32 if(str /= 'AbCdEfGh') call abort()
33 if(associated(str4)) call abort()
35 if(str4 /= str .or. len(str4)/=8) call abort()
36 if(.not.associated(str4, str)) call abort()
39 if(str4 == '12a56b78') call abort()
41 if(str == 'ABCDEFGH') call abort()
42 allocate(str5, source=str)
43 if(associated(str5, str)) call abort()
44 if(str5 /= '12a56b78' .or. len(str5)/=8) call abort()
46 if(str5 == 'abcdef') call abort()
48 if(str == 'ABCDEF') call abort()
49 end subroutine source_check
50 subroutine source_check4()
51 character(kind=4,len=:), allocatable :: str, str2
53 character(kind=4,len=8) :: str3
54 character(kind=4,len=:), pointer :: str4, str5
57 if(allocated(str)) call abort()
58 allocate(str, source=str3)
59 if(.not.allocated(str)) call abort()
60 if(len(str) /= 8) call abort()
61 if(str /= 4_'AbCdEfGh') call abort()
62 if(associated(str4)) call abort()
64 if(str4 /= str .or. len(str4)/=8) call abort()
65 if(.not.associated(str4, str)) call abort()
68 if(str4 == 4_'12a56b78') call abort()
70 if(str == 4_'ABCDEFGH') call abort()
71 allocate(str5, source=str)
72 if(associated(str5, str)) call abort()
73 if(str5 /= 4_'12a56b78' .or. len(str5)/=8) call abort()
75 if(str5 == 4_'abcdef') call abort()
77 if(str == 4_'ABCDEF') call abort()
78 end subroutine source_check4
79 subroutine mold_check()
80 character(len=:), allocatable :: str, str2
81 character(len=8) :: str3
82 character(len=:), pointer :: str4, str5
85 ALLOCATE( str, MOLD=str3)
86 if (len(str) /= 8) call abort()
88 ALLOCATE( str, MOLD=str2)
89 if (len(str) /= 4) call abort()
91 IF (associated(str4)) call abort()
92 ALLOCATE( str4, MOLD=str3)
93 IF (.not.associated(str4)) call abort()
95 if (len(str4) /= 8) call abort()
96 if(str4 /= '12345678') call abort()
98 ALLOCATE( str4, MOLD=str2)
100 if (len(str4) /= 4) call abort()
101 if (str4 /= 'ABCD') call abort()
103 if(.not.associated(str4,str5)) call abort()
104 if(len(str5) /= 4 .or. len(str4) /= len(str5)) call abort()
105 if(str5 /= str4) call abort()
107 end subroutine mold_check
108 subroutine mold_check4()
109 character(len=:,kind=4), allocatable :: str, str2
110 character(len=8,kind=4) :: str3
111 character(len=:,kind=4), pointer :: str4, str5
114 ALLOCATE( str, MOLD=str3)
115 if (len(str) /= 8) call abort()
117 ALLOCATE( str, MOLD=str2)
118 if (len(str) /= 4) call abort()
120 IF (associated(str4)) call abort()
121 ALLOCATE( str4, MOLD=str3)
122 IF (.not.associated(str4)) call abort()
124 if (len(str4) /= 8) call abort()
125 if(str4 /= 4_'12345678') call abort()
127 ALLOCATE( str4, MOLD=str2)
129 if (len(str4) /= 4) call abort()
130 if (str4 /= 4_'ABCD') call abort()
132 if(.not.associated(str4,str5)) call abort()
133 if(len(str5) /= 4 .or. len(str4) /= len(str5)) call abort()
134 if(str5 /= str4) call abort()
136 end subroutine mold_check4
137 subroutine ftn_test()
138 character(len=:), allocatable :: str_a
139 character(len=:), pointer :: str_p
141 call proc_test(str_a, str_p, .false.)
142 if (str_p /= '123457890abcdef') call abort()
143 if (len(str_p) /= 50) call abort()
144 if (str_a(1:5) /= 'ABCDE ') call abort()
145 if (len(str_a) /= 50) call abort()
148 if(len(str_a) /= 4) call abort()
149 if(str_a /= '1245') call abort()
150 allocate(character(len=6) :: str_p)
151 if(len(str_p) /= 6) call abort()
153 call proc_test(str_a, str_p, .true.)
154 if (str_p /= '123457890abcdef') call abort()
155 if (len(str_p) /= 50) call abort()
156 if (str_a(1:5) /= 'ABCDE ') call abort()
157 if (len(str_a) /= 50) call abort()
159 end subroutine ftn_test
160 subroutine proc_test(a, p, alloc)
161 character(len=:), allocatable :: a
162 character(len=:), pointer :: p
163 character(len=5), target :: loc
165 if (.not. alloc) then
166 if(associated(p)) call abort()
167 if(allocated(a)) call abort()
169 if(len(a) /= 4) call abort()
170 if(a /= '1245') call abort()
171 if(len(p) /= 6) call abort()
172 if(p /= 'AbCdEf') call abort()
176 allocate(character(len=50) :: a)
178 if(len(a) /= 50) call abort()
179 if(a(1:5) /= "ABCDE") call abort()
182 if (len(p) /= 5) call abort()
183 if (p /= '12345') call abort()
185 if (len(p) /= 5) call abort()
186 if (p /= '12345') call abort()
188 if (loc /= 'ABC ') call abort()
190 if (.not.associated(p)) call abort()
191 p = '123457890abcdef'
192 if (p /= '123457890abcdef') call abort()
193 if (len(p) /= 50) call abort()
194 end subroutine proc_test
195 subroutine ftn_test4()
196 character(len=:,kind=4), allocatable :: str_a
197 character(len=:,kind=4), pointer :: str_p
199 call proc_test4(str_a, str_p, .false.)
200 if (str_p /= 4_'123457890abcdef') call abort()
201 if (len(str_p) /= 50) call abort()
202 if (str_a(1:5) /= 4_'ABCDE ') call abort()
203 if (len(str_a) /= 50) call abort()
206 if(len(str_a) /= 4) call abort()
207 if(str_a /= 4_'1245') call abort()
208 allocate(character(len=6, kind = 4) :: str_p)
209 if(len(str_p) /= 6) call abort()
211 call proc_test4(str_a, str_p, .true.)
212 if (str_p /= 4_'123457890abcdef') call abort()
213 if (len(str_p) /= 50) call abort()
214 if (str_a(1:5) /= 4_'ABCDE ') call abort()
215 if (len(str_a) /= 50) call abort()
217 end subroutine ftn_test4
218 subroutine proc_test4(a, p, alloc)
219 character(len=:,kind=4), allocatable :: a
220 character(len=:,kind=4), pointer :: p
221 character(len=5,kind=4), target :: loc
223 if (.not. alloc) then
224 if(associated(p)) call abort()
225 if(allocated(a)) call abort()
227 if(len(a) /= 4) call abort()
228 if(a /= 4_'1245') call abort()
229 if(len(p) /= 6) call abort()
230 if(p /= 4_'AbCdEf') call abort()
234 allocate(character(len=50,kind=4) :: a)
236 if(len(a) /= 50) call abort()
237 if(a(1:5) /= 4_"ABCDE") call abort()
240 if (len(p) /= 5) call abort()
241 if (p /= 4_'12345') call abort()
243 if (len(p) /= 5) call abort()
244 if (p /= 4_'12345') call abort()
246 if (loc /= 4_'ABC ') call abort()
248 if (.not.associated(p)) call abort()
249 p = 4_'123457890abcdef'
250 if (p /= 4_'123457890abcdef') call abort()
251 if (len(p) /= 50) call abort()
252 end subroutine proc_test4
254 character(len=:, kind=1), allocatable :: a1
255 character(len=:, kind=4), allocatable :: a4
256 character(len=:, kind=1), pointer :: p1
257 character(len=:, kind=4), pointer :: p4
258 allocate(a1, source='ABC') ! << ICE
259 if(len(a1) /= 3 .or. a1 /= 'ABC') call abort()
260 allocate(a4, source=4_'12345') ! << ICE
261 if(len(a4) /= 5 .or. a4 /= 4_'12345') call abort()
262 allocate(p1, mold='AB') ! << ICE
263 if(len(p1) /= 2) call abort()
264 allocate(p4, mold=4_'145') ! << ICE
265 if(len(p4) /= 3) call abort()
266 end subroutine source3