1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Check for semantic errors in ALLOCATE statements
4 subroutine C945_a(srca
, srcb
, srcc
, src_complex
, src_logical
, &
5 srca2
, srcb2
, srcc2
, src_complex2
, srcx
, srcx2
)
6 ! If type-spec appears, it shall specify a type with which each
7 ! allocate-object is type compatible.
9 !second part C945, specific to SOURCE, is not checked here.
16 real, allocatable
:: x(:)
24 class(A
), allocatable
:: polymorph
25 type(A
), allocatable
:: notpolymorph
29 class(A
) srca
, srca2(5)
30 type(B
) srcb
, srcb2(6)
31 class(C
) srcc
, srcc2(7)
32 complex src_complex
, src_complex2(8)
33 complex src_logical(5)
34 real, allocatable
:: x1
, x2(:)
35 class(A
), allocatable
:: aa1
, aa2(:)
36 class(B
), pointer :: bp1
, bp2(:)
37 class(C
), allocatable
:: ca1
, ca2(:)
38 class(*), pointer :: up1
, up2(:)
39 type(A
), allocatable
:: npaa1
, npaa2(:)
40 type(B
), pointer :: npbp1
, npbp2(:)
41 type(C
), allocatable
:: npca1
, npca2(:)
42 class(Unrelated
), allocatable
:: unrelat
44 allocate(x1
, source
=srcx
)
45 allocate(x2
, mold
=srcx2
)
46 allocate(bp2(3)%x
, source
=srcx2
)
47 !OK, type-compatible with A
48 allocate(aa1
, up1
, unrelat
%polymorph
, unrelat
%notpolymorph
, &
50 allocate(aa2
, up2
, npaa2
, source
=srca2
)
51 !OK, type compatible with B
52 allocate(aa1
, up1
, unrelat
%polymorph
, bp1
, npbp1
, mold
=srcb
)
53 allocate(aa2
, up2
, bp2
, npbp2
, mold
=srcb2
)
54 !OK, type compatible with C
55 allocate(aa1
, up1
, unrelat
%polymorph
, bp1
, ca1
, npca1
, mold
=srcc
)
56 allocate(aa2
, up2
, bp2
, ca2
, npca2
, source
=srcc2
)
59 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
60 allocate(x1
, mold
=src_complex
)
61 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
62 allocate(x2(2), source
=src_complex2
)
63 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
64 allocate(bp2(3)%x
, mold
=src_logical
)
65 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
66 allocate(unrelat
, mold
=srca
)
67 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
68 allocate(unrelat
%notpolymorph
, source
=srcb
)
69 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
70 allocate(npaa1
, mold
=srcb
)
71 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
72 allocate(npaa2
, source
=srcb2
)
73 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
74 allocate(npca1
, bp1
, npbp1
, mold
=srcc
)
84 function f(this
) result (x
)
86 class(t
), allocatable
:: x
90 type(t
), allocatable
:: p
91 real, allocatable
:: rp
92 allocate(p
, source
=o
%f())
93 !ERROR: Allocatable object in ALLOCATE must be type compatible with source expression from MOLD or SOURCE
94 allocate(rp
, source
=o
%f())
98 ! Related to C945, check typeless expression are caught
103 function func() result(x
)
107 program test_typeless
108 class(*), allocatable
:: x
115 procedure (sub
), pointer :: subp
=> sub
116 procedure (func
), pointer :: funcp
=> func
119 allocate(x
, mold
=func())
120 allocate(x
, source
=funcp())
122 !ERROR: Typeless item not allowed as SOURCE or MOLD in ALLOCATE
123 allocate(x
, mold
=x
'1')
124 !ERROR: Typeless item not allowed as SOURCE or MOLD in ALLOCATE
125 allocate(x
, mold
=sub
)
126 !ERROR: Typeless item not allowed as SOURCE or MOLD in ALLOCATE
127 allocate(x
, source
=subp
)
128 !ERROR: Typeless item not allowed as SOURCE or MOLD in ALLOCATE
129 allocate(x
, mold
=func
)
130 !ERROR: Typeless item not allowed as SOURCE or MOLD in ALLOCATE
131 allocate(x
, source
=funcp
)