annotate gcc/testsuite/gfortran.dg/pointer_array_4.f90 @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ! { dg-do run }
kono
parents:
diff changeset
2 !
kono
parents:
diff changeset
3 ! Test the fix for PR57116 as part of the overall fix for PR34640.
kono
parents:
diff changeset
4 !
kono
parents:
diff changeset
5 ! Contributed by Reinhold Bader <Bader@lrz.de>
kono
parents:
diff changeset
6 !
kono
parents:
diff changeset
7 module mod_rtti_ptr
kono
parents:
diff changeset
8 implicit none
kono
parents:
diff changeset
9 type :: foo
kono
parents:
diff changeset
10 real :: v
kono
parents:
diff changeset
11 integer :: i
kono
parents:
diff changeset
12 end type foo
kono
parents:
diff changeset
13 contains
kono
parents:
diff changeset
14 subroutine extract(this, v, ic)
kono
parents:
diff changeset
15 class(*), target :: this(:)
kono
parents:
diff changeset
16 real, pointer :: v(:)
kono
parents:
diff changeset
17 integer :: ic
kono
parents:
diff changeset
18 select type (this)
kono
parents:
diff changeset
19 type is (real)
kono
parents:
diff changeset
20 v => this(ic:)
kono
parents:
diff changeset
21 class is (foo)
kono
parents:
diff changeset
22 v => this(ic:)%v
kono
parents:
diff changeset
23 end select
kono
parents:
diff changeset
24 end subroutine extract
kono
parents:
diff changeset
25 end module
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 program prog_rtti_ptr
kono
parents:
diff changeset
28 use mod_rtti_ptr
kono
parents:
diff changeset
29 class(*), allocatable, target :: o(:)
kono
parents:
diff changeset
30 real, pointer :: v(:)
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 allocate(o(3), source=[1.0, 2.0, 3.0])
kono
parents:
diff changeset
33 call extract(o, v, 2)
kono
parents:
diff changeset
34 if (size(v) == 2 .and. all (v == [2.0, 3.0])) then
kono
parents:
diff changeset
35 deallocate(o)
kono
parents:
diff changeset
36 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
37 STOP 1
111
kono
parents:
diff changeset
38 end if
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 allocate(o(3), source=[foo(1.0, 1), foo(4.0, 4), foo(5.0, 5)])
kono
parents:
diff changeset
41 call extract(o, v, 2)
kono
parents:
diff changeset
42 if (size(v) == 2 .and. all (v == [4.0, 5.0])) then
kono
parents:
diff changeset
43 deallocate(o)
kono
parents:
diff changeset
44 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
45 STOP 2
111
kono
parents:
diff changeset
46 end if
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 ! The rest tests the case in comment 2 <janus@gcc.gnu.org>
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 call extract1 (v, 1)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 if (any (v /= [1.0, 2.0])) STOP 3
111
kono
parents:
diff changeset
52 call extract1 (v, 2) ! Call to deallocate pointer.
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 contains
kono
parents:
diff changeset
55 subroutine extract1(v, flag)
kono
parents:
diff changeset
56 type :: foo
kono
parents:
diff changeset
57 real :: v
kono
parents:
diff changeset
58 character(4) :: str
kono
parents:
diff changeset
59 end type
kono
parents:
diff changeset
60 class(foo), pointer, save :: this(:)
kono
parents:
diff changeset
61 real, pointer :: v(:)
kono
parents:
diff changeset
62 integer :: flag
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 if (flag == 1) then
kono
parents:
diff changeset
65 allocate (this(2), source = [foo (1.0, "one "), foo (2.0, "two ")])
kono
parents:
diff changeset
66 select type (this)
kono
parents:
diff changeset
67 class is (foo)
kono
parents:
diff changeset
68 v => this(1:2)%v
kono
parents:
diff changeset
69 end select
kono
parents:
diff changeset
70 else
kono
parents:
diff changeset
71 deallocate (this)
kono
parents:
diff changeset
72 end if
kono
parents:
diff changeset
73 end subroutine
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 end program prog_rtti_ptr