PR tree-optimization/86415 - strlen() not folded for substrings within constant arrays
[official-gcc.git] / gcc / testsuite / gfortran.dg / char_pointer_func.f90
blob6338b380971a088069bb7e7645d507c9d2d22156
1 ! { dg-do run }
2 ! { dg-options "-std=legacy" }
4 program char_pointer_func
5 ! Test assignments from character pointer functions, required
6 ! to fix PR17192 and PR17202
7 ! Provided by Paul Thomas pault@gcc.gnu.org
8 implicit none
9 character*4 :: c0
10 character*4, pointer :: c1
11 character*4, pointer :: c2(:)
12 allocate (c1, c2(1))
13 ! Check that we have not broken non-pointer characters.
14 c0 = foo ()
15 if (c0 /= "abcd") STOP 1
16 ! Value assignments
17 c1 = sfoo ()
18 if (c1 /= "abcd") STOP 2
19 c2 = afoo (c0)
20 if (c2(1) /= "abcd") STOP 3
21 deallocate (c1, c2)
22 ! Pointer assignments
23 c1 => sfoo ()
24 if (c1 /= "abcd") STOP 4
25 c2 => afoo (c0)
26 if (c2(1) /= "abcd") STOP 5
27 deallocate (c1, c2)
28 contains
29 function foo () result (cc1)
30 character*4 :: cc1
31 cc1 = "abcd"
32 end function foo
33 function sfoo () result (sc1)
34 character*4, pointer :: sc1
35 allocate (sc1)
36 sc1 = "abcd"
37 end function sfoo
38 function afoo (c0) result (ac1)
39 character*4 :: c0
40 character*4, pointer :: ac1(:)
41 allocate (ac1(1))
42 ac1 = "abcd"
43 end function afoo
44 end program char_pointer_func