1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Check for semantic errors in ALLOCATE statements
4 subroutine C941_C942b_C950(xsrc
, x1
, a2
, b2
, cx1
, ca2
, cb1
, cb2
, c1
, c2
)
5 ! C941: An allocate-coarray-spec shall appear if and only if the allocate-object
8 real, allocatable
:: array(:)
11 class(type0
), pointer :: t0
15 type(type1
), pointer :: t1(:)
23 real, allocatable
:: x(:)
27 class(type2
), allocatable
:: ct2(:, :)[:, :, :]
28 class(A
), allocatable
:: cx(:, :)[:, :, :]
29 class(A
), allocatable
:: x(:, :)
33 real, allocatable
:: x1
, x2(:)
34 class(A
), pointer :: a1
, a2(:)
36 real, allocatable
:: cx1
[:], cx2(:)[:, :]
37 class(A
), allocatable
:: ca1
[:, :], ca2(:)[:]
40 type(B
) :: cb1
[5:*], cb2(*)[2, -1:*]
44 pointer :: varLocal(:)
46 class(*), allocatable
:: var(:), cvar(:)[:]
49 allocate(x1
, x2(10), cx1
[*], cx2(10)[2, -1:*])
50 allocate(a1
, a2(10), ca1
[2, -1:*], ca2(10)[*])
51 allocate(b1
%x
, b2(1)%x
, cb1
%x
, cb2(1)%x
, SOURCE
=xsrc
)
52 allocate(c1
%x(-1:10, 1:5), c1
%cx(-1:10, 1:5)[-1:5, 1:2, 2:*])
54 allocate(varLocal(64))
55 allocate(A
:: var(5), cvar(10)[*])
58 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
60 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
62 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
64 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
67 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
68 allocate(cx1
[*], a1
[*])
69 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
70 allocate(cx1
[*], a2(10)[*])
71 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
73 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
74 allocate(ca1
[2, -1:*], ca2(10))
76 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
77 allocate(b1
%x
[5:*] , SOURCE
=xsrc
)
78 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
79 allocate(b2(1)%x
[2, -1:*], SOURCE
=xsrc
)
80 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
81 allocate(cb1
%x
[5:*] , SOURCE
=xsrc
)
82 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
83 allocate(cb2(1)%x
[2, -1:*], SOURCE
=xsrc
)
85 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
86 allocate(c1
%x(-1:10, 1:5)[-1:5, 1:2, 2:*])
87 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
88 allocate(c1
%cx(-1:10, 1:5))
90 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray
91 allocate(A
:: var(5)[*], cvar(10)[*])
92 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray
93 allocate(A
:: var(5), cvar(10))
95 ! C942b: [... (shape related stuff not tested here) ...]. The number of
96 ! allocate-coshape-specs in an allocate-coarray-spec shall be one less
97 ! than the corank of the allocate-object.
99 ! Valid constructs already tested above
101 !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
102 allocate(cx1
[2,-1:*], cx2(10)[2, -1:*])
103 !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
104 allocate(ca1
[*], ca2(10)[*])
105 !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
106 allocate(c1
%cx(-1:10, 1:5)[-1:5, 1:*])
107 !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray
108 allocate(A
:: cvar(10)[2,2,*])
110 ! C950: An allocate-object shall not be a coindexed object.
113 allocate(c1
%ct2(2,5)%t1(2)%t0
%array(10))
115 !ERROR: Allocatable object must not be coindexed in ALLOCATE
116 allocate(b1
%x
, b2(1)%x
, cb1
[2]%x
, SOURCE
=xsrc
)
117 !ERROR: Allocatable object must not be coindexed in ALLOCATE
118 allocate(b1
%x
, b2(1)%x
, cb2(1)[2,-1]%x
, MOLD
=xsrc
)
119 !ERROR: Allocatable object must not be coindexed in ALLOCATE
120 allocate(c1
%ct2(2,5)[1,1,1]%t1(2)%t0
%array(10))