aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/allocate_deferred_char_scalar_1.f03
blob: b9b70401412c2e203083e98d8e642289410ada94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
! { dg-do run }
!
! Automatic reallocate on assignment, deferred length parameter for char
!
! PR fortran/45170
! PR fortran/35810
! PR fortran/47350
!
! Contributed by Tobias Burnus  <burnus@gcc.gnu.org>
!
program test
  implicit none
  call mold_check()
  call mold_check4()
  call source_check()
  call source_check4()
  call ftn_test()
  call ftn_test4()
  call source3()
contains
  subroutine source_check()
    character(len=:), allocatable :: str, str2
    target :: str
    character(len=8) :: str3
    character(len=:), pointer :: str4, str5
    nullify(str4)
    str3 = 'AbCdEfGhIj'
    if(allocated(str)) call abort()
    allocate(str, source=str3)
    if(.not.allocated(str)) call abort()
    if(len(str) /= 8) call abort()
    if(str /= 'AbCdEfGh') call abort()
    if(associated(str4)) call abort()
    str4 => str
    if(str4 /= str .or. len(str4)/=8) call abort()
    if(.not.associated(str4, str)) call abort()
    str4 => null()
    str = '12a56b78'
    if(str4 == '12a56b78') call abort()
    str4 = 'ABCDEFGH'
    if(str == 'ABCDEFGH') call abort()
    allocate(str5, source=str)
    if(associated(str5, str)) call abort()
    if(str5 /= '12a56b78' .or. len(str5)/=8) call abort()
    str = 'abcdef'
    if(str5 == 'abcdef') call abort()
    str5 = 'ABCDEF'
    if(str == 'ABCDEF') call abort()
  end subroutine source_check
  subroutine source_check4()
    character(kind=4,len=:), allocatable :: str, str2
    target :: str
    character(kind=4,len=8) :: str3
    character(kind=4,len=:), pointer :: str4, str5
    nullify(str4)
    str3 = 4_'AbCdEfGhIj'
    if(allocated(str)) call abort()
    allocate(str, source=str3)
    if(.not.allocated(str)) call abort()
    if(len(str) /= 8) call abort()
    if(str /= 4_'AbCdEfGh') call abort()
    if(associated(str4)) call abort()
    str4 => str
    if(str4 /= str .or. len(str4)/=8) call abort()
    if(.not.associated(str4, str)) call abort()
    str4 => null()
    str = 4_'12a56b78'
    if(str4 == 4_'12a56b78') call abort()
    str4 = 4_'ABCDEFGH'
    if(str == 4_'ABCDEFGH') call abort()
    allocate(str5, source=str)
    if(associated(str5, str)) call abort()
    if(str5 /= 4_'12a56b78' .or. len(str5)/=8) call abort()
    str = 4_'abcdef'
    if(str5 == 4_'abcdef') call abort()
    str5 = 4_'ABCDEF'
    if(str == 4_'ABCDEF') call abort()
  end subroutine source_check4
  subroutine mold_check()
    character(len=:), allocatable :: str, str2
    character(len=8) :: str3
    character(len=:), pointer :: str4, str5
    nullify(str4)
    str2 = "ABCE"
    ALLOCATE( str, MOLD=str3)
    if (len(str) /= 8) call abort()
    DEALLOCATE(str)
    ALLOCATE( str, MOLD=str2)
    if (len(str) /= 4) call abort()

    IF (associated(str4)) call abort()
    ALLOCATE( str4, MOLD=str3)
    IF (.not.associated(str4)) call abort()
    str4 = '12345678'
    if (len(str4) /= 8) call abort()
    if(str4 /= '12345678') call abort()
    DEALLOCATE(str4)
    ALLOCATE( str4, MOLD=str2)
    str4 = 'ABCD'
    if (len(str4) /= 4) call abort()
    if (str4 /= 'ABCD') call abort()
    str5 => str4
    if(.not.associated(str4,str5)) call abort()
    if(len(str5) /= 4 .or. len(str4) /= len(str5)) call abort()
    if(str5 /= str4) call abort()
    deallocate(str4) 
  end subroutine mold_check
  subroutine mold_check4()
    character(len=:,kind=4), allocatable :: str, str2
    character(len=8,kind=4) :: str3
    character(len=:,kind=4), pointer :: str4, str5
    nullify(str4)
    str2 = 4_"ABCE"
    ALLOCATE( str, MOLD=str3)
    if (len(str) /= 8) call abort()
    DEALLOCATE(str)
    ALLOCATE( str, MOLD=str2)
    if (len(str) /= 4) call abort()

    IF (associated(str4)) call abort()
    ALLOCATE( str4, MOLD=str3)
    IF (.not.associated(str4)) call abort()
    str4 = 4_'12345678'
    if (len(str4) /= 8) call abort()
    if(str4 /= 4_'12345678') call abort()
    DEALLOCATE(str4)
    ALLOCATE( str4, MOLD=str2)
    str4 = 4_'ABCD'
    if (len(str4) /= 4) call abort()
    if (str4 /= 4_'ABCD') call abort()
    str5 => str4
    if(.not.associated(str4,str5)) call abort()
    if(len(str5) /= 4 .or. len(str4) /= len(str5)) call abort()
    if(str5 /= str4) call abort()
    deallocate(str4) 
  end subroutine mold_check4
  subroutine ftn_test()
    character(len=:), allocatable :: str_a
    character(len=:), pointer     :: str_p
    nullify(str_p) 
    call proc_test(str_a, str_p, .false.)
    if (str_p /= '123457890abcdef') call abort()
    if (len(str_p) /= 50) call abort()
    if (str_a(1:5) /= 'ABCDE ') call abort()
    if (len(str_a) /= 50) call abort()
    deallocate(str_p)
    str_a = '1245'
    if(len(str_a) /= 4) call abort()
    if(str_a /= '1245') call abort()
    allocate(character(len=6) :: str_p)
    if(len(str_p) /= 6) call abort()
    str_p = 'AbCdEf'
    call proc_test(str_a, str_p, .true.)
    if (str_p /= '123457890abcdef') call abort()
    if (len(str_p) /= 50) call abort()
    if (str_a(1:5) /= 'ABCDE ') call abort()
    if (len(str_a) /= 50) call abort()
    deallocate(str_p)
  end subroutine ftn_test
  subroutine proc_test(a, p, alloc)
    character(len=:), allocatable :: a
    character(len=:), pointer     :: p
    character(len=5), target :: loc
    logical :: alloc
    if (.not.  alloc) then
      if(associated(p)) call abort()
      if(allocated(a)) call abort()
    else
      if(len(a) /= 4) call abort()
      if(a /= '1245') call abort()
      if(len(p) /= 6) call abort()
      if(p /= 'AbCdEf') call abort()
      deallocate(a)
      nullify(p)
    end if
    allocate(character(len=50) :: a)
    a(1:5) = 'ABCDE'
    if(len(a) /= 50) call abort()
    if(a(1:5) /= "ABCDE") call abort()
    loc = '12345'
    p => loc
    if (len(p) /= 5) call abort()
    if (p /= '12345') call abort()
    p = '12345679'
    if (len(p) /= 5) call abort()
    if (p /= '12345') call abort()
    p = 'ABC'
    if (loc /= 'ABC  ') call abort()
    allocate(p, mold=a)
    if (.not.associated(p)) call abort()
    p = '123457890abcdef'
    if (p /= '123457890abcdef') call abort()
    if (len(p) /= 50) call abort()
  end subroutine proc_test
  subroutine ftn_test4()
    character(len=:,kind=4), allocatable :: str_a
    character(len=:,kind=4), pointer     :: str_p
    nullify(str_p) 
    call proc_test4(str_a, str_p, .false.)
    if (str_p /= 4_'123457890abcdef') call abort()
    if (len(str_p) /= 50) call abort()
    if (str_a(1:5) /= 4_'ABCDE ') call abort()
    if (len(str_a) /= 50) call abort()
    deallocate(str_p)
    str_a = 4_'1245'
    if(len(str_a) /= 4) call abort()
    if(str_a /= 4_'1245') call abort()
    allocate(character(len=6, kind = 4) :: str_p)
    if(len(str_p) /= 6) call abort()
    str_p = 4_'AbCdEf'
    call proc_test4(str_a, str_p, .true.)
    if (str_p /= 4_'123457890abcdef') call abort()
    if (len(str_p) /= 50) call abort()
    if (str_a(1:5) /= 4_'ABCDE ') call abort()
    if (len(str_a) /= 50) call abort()
    deallocate(str_p)
  end subroutine ftn_test4
  subroutine proc_test4(a, p, alloc)
    character(len=:,kind=4), allocatable :: a
    character(len=:,kind=4), pointer     :: p
    character(len=5,kind=4), target :: loc
    logical :: alloc
    if (.not.  alloc) then
      if(associated(p)) call abort()
      if(allocated(a)) call abort()
    else
      if(len(a) /= 4) call abort()
      if(a /= 4_'1245') call abort()
      if(len(p) /= 6) call abort()
      if(p /= 4_'AbCdEf') call abort()
      deallocate(a)
      nullify(p)
    end if
    allocate(character(len=50,kind=4) :: a)
    a(1:5) = 4_'ABCDE'
    if(len(a) /= 50) call abort()
    if(a(1:5) /= 4_"ABCDE") call abort()
    loc = '12345'
    p => loc
    if (len(p) /= 5) call abort()
    if (p /= 4_'12345') call abort()
    p = 4_'12345679'
    if (len(p) /= 5) call abort()
    if (p /= 4_'12345') call abort()
    p = 4_'ABC'
    if (loc /= 4_'ABC  ') call abort()
    allocate(p, mold=a)
    if (.not.associated(p)) call abort()
    p = 4_'123457890abcdef'
    if (p /= 4_'123457890abcdef') call abort()
    if (len(p) /= 50) call abort()
  end subroutine proc_test4
  subroutine source3()
     character(len=:, kind=1), allocatable :: a1
     character(len=:, kind=4), allocatable :: a4
     character(len=:, kind=1), pointer     :: p1
     character(len=:, kind=4), pointer     :: p4
     allocate(a1, source='ABC') ! << ICE
     if(len(a1) /= 3 .or. a1 /= 'ABC') call abort()
     allocate(a4, source=4_'12345') ! << ICE
     if(len(a4) /= 5 .or. a4 /= 4_'12345') call abort()
     allocate(p1, mold='AB') ! << ICE
     if(len(p1) /= 2) call abort()
     allocate(p4, mold=4_'145') ! << ICE
     if(len(p4) /= 3) call abort()
  end subroutine source3
end program test