1 ! RUN: %S/test_errors.sh %s %t %flang_fc1
3 ! Check for semantic errors in ALLOCATE statements
5 subroutine C933_a(b1
, ca3
, ca4
, cp3
, cp3mold
, cp4
, cp7
, cp8
, bsrc
)
6 ! If any allocate-object has a deferred type parameter, is unlimited polymorphic,
7 ! or is of abstract type, either type-spec or source-expr shall appear.
9 ! Only testing deferred type parameters here.
11 type SomeType(k
, l1
, l2
)
12 integer, kind
:: k
= 1
14 integer, len
:: l2
= 3
15 character(len
=l2
+l1
) str
20 character(:), allocatable
:: msg
21 type(SomeType(4, l
, :)), pointer :: something
24 character(len
=:), allocatable
:: ca1
, ca2(:)
25 character(len
=*), allocatable
:: ca3
, ca4(:)
26 character(len
=2), allocatable
:: ca5
, ca6(:)
29 type(SomeType(l1
=:,l2
=:)), pointer :: cp1
, cp2(:)
30 type(SomeType(l1
=3,l2
=4)) cp1mold
31 type(SomeType(1,*,:)), pointer :: cp3
, cp4(:)
32 type(SomeType(1,*,5)) cp3mold
33 type(SomeType(l1
=:)), pointer :: cp5
, cp6(:)
34 type(SomeType(l1
=6)) cp5mold
35 type(SomeType(1,*,*)), pointer :: cp7
, cp8(:)
36 type(SomeType(1, l1
=3)), pointer :: cp9
, cp10(:)
39 type(B(:)), allocatable
:: b2
42 type(SomeType(4, *, 8)) bsrc
44 ! Expecting errors: need type-spec/src-expr
45 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
47 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
49 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
51 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
53 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
55 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
57 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
59 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
61 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
63 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
64 allocate(b1
%something
)
65 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
67 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
68 allocate(b2
%something
)
69 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
71 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
72 allocate(b3
%something
)
74 ! Nominal cases, expecting no errors
75 allocate(character(len
=5):: ca2(4))
76 allocate(character(len
=5):: ca1
)
77 allocate(character*5:: ca1
)
78 allocate(ca2(4), MOLD
= "abcde")
79 allocate(ca2(2), MOLD
= (/"abcde", "fghij"/))
80 allocate(ca1
, MOLD
= mold
)
81 allocate(ca2(4), SOURCE
= "abcde")
82 allocate(ca2(2), SOURCE
= (/"abcde", "fghij"/))
83 allocate(ca1
, SOURCE
= mold
)
84 allocate(SomeType(l1
=1, l2
=2):: cp1
, cp2(2))
85 allocate(SomeType(1,*,5):: cp3
, cp4(2)) !OK, but segfaults gfortran
86 allocate(SomeType(l1
=1):: cp5
, cp6(2))
87 allocate(cp1
, cp2(2), mold
= cp1mold
)
88 allocate(cp3
, cp4(2), mold
= cp3mold
)
89 allocate(cp5
, cp6(2), mold
= cp5mold
)
90 allocate(cp1
, cp2(2), source
= cp1mold
)
91 allocate(cp3
, cp4(2), source
= cp3mold
)
92 allocate(cp5
, cp6(2), source
= cp5mold
)
93 allocate(character(len
=10):: b1
%msg
, b2
%msg
, b3
%msg
)
94 allocate(SomeType(4, b1
%l
, 9):: b1
%something
)
95 allocate(b2
%something
, source
=bsrc
)
96 allocate(SomeType(4, 5, 8):: b3
%something
)
98 ! assumed/explicit length do not need type-spec/mold
100 allocate(ca5
, ca6(4))
101 allocate(cp7
, cp8(2))
102 allocate(cp9
, cp10(2))