aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/select_type_8.f03
blob: 306f2d18286b31856ec26a47f488eb5737d23443 (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
! { dg-do run }
!
! executing SELECT TYPE statements with CLASS IS blocks
!
! Contributed by Janus Weil <janus@gcc.gnu.org>

  implicit none

  type :: t1
    integer :: i
  end type t1

  type, extends(t1) :: t2
    integer :: j
  end type t2

  type, extends(t2) :: t3
    real :: r
  end type

  class(t1), pointer :: cp
  type(t1), target :: a
  type(t2), target :: b
  type(t3), target :: c
  integer :: i

  cp => c
  i = 0
  select type (cp)
  type is (t1)
    i = 1
  type is (t2)
    i = 2
  class is (t1)
    i = 3
  class default
    i = 4
  end select
  print *,i
  if (i /= 3) call abort()

  cp => a
  select type (cp)
  type is (t1)
    i = 1
  type is (t2)
    i = 2
  class is (t1)
    i = 3
  end select
  print *,i
  if (i /= 1) call abort()

  cp => b
  select type (cp)
  type is (t1)
    i = 1
  class is (t3)
    i = 3
  class is (t2)
    i = 4
  class is (t1)
    i = 5
  end select
  print *,i
  if (i /= 4) call abort()

  cp => b
  select type (cp)
  type is (t1)
    i = 1
  class is (t1)
    i = 5
  class is (t2)
    i = 4
  class is (t3)
    i = 3
  end select
  print *,i
  if (i /= 4) call abort()

  cp => a
  select type (cp)
  type is (t2)
    i = 1
  class is (t2)
    i = 2
  class default
    i = 3
  class is (t3)
    i = 4
  type is (t3)
    i = 5
  end select
  print *,i
  if (i /= 3) call abort()

end