111
|
1 ! { dg-do run }
|
|
2 !
|
|
3 ! PR 43388: [F2008][OOP] ALLOCATE with MOLD=
|
|
4 !
|
|
5 ! Contributed by Janus Weil <janus@gcc.gnu.org>
|
|
6
|
|
7 type :: t1
|
|
8 integer :: i
|
|
9 end type
|
|
10
|
|
11 type,extends(t1) :: t2
|
|
12 integer :: j = 4
|
|
13 end type
|
|
14
|
|
15 class(t1),allocatable :: x,y
|
|
16 type(t2) :: z
|
|
17
|
|
18
|
|
19 !!! first example (static)
|
|
20
|
|
21 z%j = 5
|
|
22 allocate(x,MOLD=z)
|
|
23
|
|
24 select type (x)
|
|
25 type is (t2)
|
|
26 print *,x%j
|
131
|
27 if (x%j/=4) STOP 1
|
111
|
28 x%j = 5
|
|
29 class default
|
131
|
30 STOP 1
|
111
|
31 end select
|
|
32
|
|
33
|
|
34 !!! second example (dynamic, PR 44541)
|
|
35
|
|
36 allocate(y,MOLD=x)
|
|
37
|
|
38 select type (y)
|
|
39 type is (t2)
|
|
40 print *,y%j
|
131
|
41 if (y%j/=4) STOP 2
|
111
|
42 class default
|
131
|
43 STOP 2
|
111
|
44 end select
|
|
45
|
|
46 end
|