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