• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1! RUN: %S/test_errors.sh %s %t %f18
2! Check for semantic errors in ALLOCATE statements
3
4
5subroutine C934()
6! If type-spec appears, it shall specify a type with which each
7! allocate-object is type compatible.
8
9  type A
10    integer i
11  end type
12
13  type, extends(A) :: B
14    real, allocatable :: x(:)
15  end type
16
17  type, extends(B) :: C
18    character(5) s
19  end type
20
21  type Unrelated
22    class(A), allocatable :: polymorph
23    type(A), allocatable :: notpolymorph
24  end type
25
26  real, allocatable :: x1, x2(:)
27  class(A), allocatable :: aa1, aa2(:)
28  class(B), pointer :: bp1, bp2(:)
29  class(C), allocatable :: ca1, ca2(:)
30  class(*), pointer :: up1, up2(:)
31  type(A), allocatable :: npaa1, npaa2(:)
32  type(B), pointer :: npbp1, npbp2(:)
33  type(C), allocatable :: npca1, npca2(:)
34  class(Unrelated), allocatable :: unrelat
35
36  allocate(real:: x1)
37  allocate(real:: x2(2))
38  allocate(real:: bp2(3)%x(5))
39  !OK, type-compatible with A
40  allocate(A:: aa1, aa2(2), up1, up2(3), &
41    unrelat%polymorph, unrelat%notpolymorph, npaa1, npaa2(4))
42  !OK, type compatible with B
43  allocate(B:: aa1, aa2(2), up1, up2(3), &
44    unrelat%polymorph, bp1, bp2(2), npbp1, npbp2(2:4))
45  !OK, type compatible with C
46  allocate(C:: aa1, aa2(2), up1, up2(3), &
47    unrelat%polymorph, bp1, bp2(2), ca1, ca2(4), &
48    npca1, npca2(2:4))
49
50
51  !ERROR: Allocatable object in ALLOCATE must be type compatible with type-spec
52  allocate(complex:: x1)
53  !ERROR: Allocatable object in ALLOCATE must be type compatible with type-spec
54  allocate(complex:: x2(2))
55  !ERROR: Allocatable object in ALLOCATE must be type compatible with type-spec
56  allocate(logical:: bp2(3)%x(5))
57  !ERROR: Allocatable object in ALLOCATE must be type compatible with type-spec
58  allocate(A:: unrelat)
59  !ERROR: Allocatable object in ALLOCATE must be type compatible with type-spec
60  allocate(B:: unrelat%notpolymorph)
61  !ERROR: Allocatable object in ALLOCATE must be type compatible with type-spec
62  allocate(B:: npaa1)
63  !ERROR: Allocatable object in ALLOCATE must be type compatible with type-spec
64  allocate(B:: npaa2(4))
65  !ERROR: Allocatable object in ALLOCATE must be type compatible with type-spec
66  allocate(C:: npca1, bp1, npbp1)
67end subroutine
68