PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gfortran.dg / unlimited_polymorphic_20.f90
blobf0d83a3620dc4bc507b78debc5b6c488b5ae9533
1 ! { dg-do run }
3 ! Testing fix for PR fortran/60255
5 ! Author: Andre Vehreschild <vehre@gmx.de>
7 MODULE m
9 contains
10 subroutine bar (arg, res)
11 class(*) :: arg
12 character(100) :: res
13 select type (w => arg)
14 type is (character(*))
15 write (res, '(I2)') len(w)
16 end select
17 end subroutine
19 END MODULE
21 program test
22 use m;
23 implicit none
24 character(LEN=:), allocatable, target :: S
25 character(LEN=100) :: res
26 class(*), pointer :: ucp, ucp2
27 call sub1 ("long test string", 16)
28 call sub2 ()
29 S = "test"
30 ucp => S
31 call sub3 (ucp)
32 allocate (ucp2, source=ucp)
33 call sub3 (ucp2)
34 call sub4 (S, 4)
35 call sub4 ("This is a longer string.", 24)
36 call bar (S, res)
37 if (trim (res) .NE. " 4") STOP 1
38 call bar(ucp, res)
39 if (trim (res) .NE. " 4") STOP 2
41 contains
43 subroutine sub1(dcl, ilen)
44 character(len=*), target :: dcl
45 integer(4) :: ilen
46 character(len=:), allocatable :: hlp
47 class(*), pointer :: ucp
49 ucp => dcl
51 select type (ucp)
52 type is (character(len=*))
53 if (len(dcl) .NE. ilen) STOP 3
54 if (len(ucp) .NE. ilen) STOP 4
55 hlp = ucp
56 if (len(hlp) .NE. ilen) STOP 5
57 class default
58 STOP 6
59 end select
60 end subroutine
62 subroutine sub2
63 character(len=:), allocatable, target :: dcl
64 class(*), pointer :: ucp
66 dcl = "ttt"
67 ucp => dcl
69 select type (ucp)
70 type is (character(len=*))
71 if (len(ucp) .ne. 3) STOP 7
72 class default
73 STOP 8
74 end select
75 end subroutine
77 subroutine sub3(ucp)
78 character(len=:), allocatable :: hlp
79 class(*), pointer :: ucp
81 select type (ucp)
82 type is (character(len=*))
83 if (len(ucp) .ne. 4) STOP 9
84 hlp = ucp
85 if (len(hlp) .ne. 4) STOP 10
86 class default
87 STOP 11
88 end select
89 end subroutine
91 subroutine sub4(ucp, ilen)
92 character(len=:), allocatable :: hlp
93 integer(4) :: ilen
94 class(*) :: ucp
96 select type (ucp)
97 type is (character(len=*))
98 if (len(ucp) .ne. ilen) STOP 12
99 hlp = ucp
100 if (len(hlp) .ne. ilen) STOP 13
101 class default
102 STOP 14
103 end select
104 end subroutine
105 end program