Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Semantics / allocate05.f90
blobeca6c9a7bc64cba4993c51dc228a391ec45be4d7
1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Check for semantic errors in ALLOCATE statements
5 subroutine C934()
6 ! If type-spec appears, it shall specify a type with which each
7 ! allocate-object is type compatible.
9 type A
10 integer i
11 end type
13 type, extends(A) :: B
14 real, allocatable :: x(:)
15 end type
17 type, extends(B) :: C
18 character(5) s
19 end type
21 type Unrelated
22 class(A), allocatable :: polymorph
23 type(A), allocatable :: notpolymorph
24 end type
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
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))
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)
67 end subroutine