1! RUN: %S/test_errors.sh %s %t %flang_fc1
2! REQUIRES: shell
3! Check for semantic errors in ALLOCATE statements
4
5subroutine C941_C942b_C950(xsrc, x1, a2, b2, cx1, ca2, cb1, cb2, c1, c2)
6! C941: An allocate-coarray-spec shall appear if and only if the allocate-object
7! is a coarray.
8  type type0
9    real, allocatable :: array(:)
10  end type
11  type type1
12    class(type0), pointer :: t0
13  end type
14
15  type type2
16    type(type1), pointer :: t1(:)
17  end type
18
19  type A
20    real x(10)
21  end type
22
23  type B
24    real, allocatable :: x(:)
25  end type
26
27  type C
28    class(type2), allocatable :: ct2(:, :)[:, :, :]
29    class(A), allocatable :: cx(:, :)[:, :, :]
30    class(A), allocatable :: x(:, :)
31  end type
32
33  real :: xsrc(10)
34  real, allocatable :: x1, x2(:)
35  class(A), pointer :: a1, a2(:)
36
37  real, allocatable :: cx1[:], cx2(:)[:, :]
38  class(A), allocatable :: ca1[:, :], ca2(:)[:]
39
40  type(B) :: b1, b2(*)
41  type(B) :: cb1[5:*], cb2(*)[2, -1:*]
42
43  type(C) :: c1
44  pointer :: c2(:, :)
45  pointer :: varLocal(:)
46
47  class(*), allocatable :: var(:), cvar(:)[:]
48
49  ! Valid constructs
50  allocate(x1, x2(10), cx1[*], cx2(10)[2, -1:*])
51  allocate(a1, a2(10), ca1[2, -1:*], ca2(10)[*])
52  allocate(b1%x, b2(1)%x, cb1%x, cb2(1)%x, SOURCE=xsrc)
53  allocate(c1%x(-1:10, 1:5), c1%cx(-1:10, 1:5)[-1:5, 1:2, 2:*])
54  allocate(c2(9, 27))
55  allocate(varLocal(64))
56  allocate(A:: var(5), cvar(10)[*])
57
58
59  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
60  allocate(x1[*])
61  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
62  allocate(x2(10)[*])
63  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
64  allocate(cx1)
65  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
66  allocate(cx2(10))
67
68  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
69  allocate(cx1[*], a1[*])
70  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
71  allocate(cx1[*], a2(10)[*])
72  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
73  allocate(x1, ca1)
74  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
75  allocate(ca1[2, -1:*], ca2(10))
76
77  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
78  allocate(b1%x[5:*] , SOURCE=xsrc)
79  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
80  allocate(b2(1)%x[2, -1:*], SOURCE=xsrc)
81  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
82  allocate(cb1%x[5:*] , SOURCE=xsrc)
83  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
84  allocate(cb2(1)%x[2, -1:*], SOURCE=xsrc)
85
86  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
87  allocate(c1%x(-1:10, 1:5)[-1:5, 1:2, 2:*])
88  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
89  allocate(c1%cx(-1:10, 1:5))
90
91  !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
92  allocate(A:: var(5)[*], cvar(10)[*])
93  !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
94  allocate(A:: var(5), cvar(10))
95
96! C942b: [... (shape related stuff not tested here) ...]. The number of
97! allocate-coshape-specs in an allocate-coarray-spec shall be one less
98! than the corank of the allocate-object.
99
100  ! Valid constructs already tested above
101
102  !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
103  allocate(cx1[2,-1:*], cx2(10)[2, -1:*])
104  !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
105  allocate(ca1[*], ca2(10)[*])
106  !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
107  allocate(c1%cx(-1:10, 1:5)[-1:5, 1:*])
108  !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
109  allocate(A:: cvar(10)[2,2,*])
110
111! C950: An allocate-object shall not be a coindexed object.
112
113  ! Valid construct
114  allocate(c1%ct2(2,5)%t1(2)%t0%array(10))
115
116  !ERROR: Allocatable object must not be coindexed in ALLOCATE
117  allocate(b1%x, b2(1)%x, cb1[2]%x, SOURCE=xsrc)
118  !ERROR: Allocatable object must not be coindexed in ALLOCATE
119  allocate(b1%x, b2(1)%x, cb2(1)[2,-1]%x, MOLD=xsrc)
120  !ERROR: Allocatable object must not be coindexed in ALLOCATE
121  allocate(c1%ct2(2,5)[1,1,1]%t1(2)%t0%array(10))
122
123end subroutine
124