1 ! RUN: %S/test_errors.sh %s %t %flang_fc1
3 ! Check for semantic errors in ALLOCATE statements
7 ! If any allocate-object has a deferred type parameter, is unlimited polymorphic,
8 ! or is of abstract type, either type-spec or source-expr shall appear.
10 ! only testing unlimited polymorphic and abstract-type here
12 type, abstract
:: Base
16 type, extends(Base
) :: A
20 type, extends(Base
) :: B
21 class(Base
), allocatable
:: y
25 class(*), pointer :: whatever
30 class(*), allocatable
:: u1
, u2(:)
31 class(C
), allocatable
:: n1
, n2(:)
32 class(Base
), pointer :: p1
, p2(:)
33 class(B
), pointer :: p3
, p4(:)
34 type(A
) :: molda
= A(1, 2)
36 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is unlimited polymorphic
38 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is unlimited polymorphic
40 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is unlimited polymorphic
42 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is unlimited polymorphic
43 allocate(n2(2)%whatever
)
44 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is of abstract type
46 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is of abstract type
48 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is of abstract type
50 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is of abstract type
52 !WRONG allocate(Base:: u1)
55 allocate(real:: u1
, u2(2))
56 allocate(A
:: u1
, u2(2))
57 allocate(C
:: u1
, u2(2))
58 allocate(character(n
):: u1
, u2(2))
59 allocate(C
:: n1
%whatever
, n2(2)%whatever
)
60 allocate(A
:: p1
, p2(2))
61 allocate(B
:: p3
%y
, p4(2)%y
)
62 allocate(u1
, u2(2), MOLD
= cos(5.+n
))
63 allocate(u1
, u2(2), MOLD
= molda
)
64 allocate(u1
, u2(2), MOLD
= n1
)
65 allocate(u1
, u2(2), MOLD
= new_line("a"))
66 allocate(n1
%whatever
, MOLD
= n2(1))
67 allocate(p1
, p2(2), MOLD
= p3
)
68 allocate(p3
%y
, p4(2)%y
, MOLD
= B(5))
69 allocate(u1
, u2(2), SOURCE
= cos(5.+n
))
70 allocate(u1
, u2(2), SOURCE
= molda
)
71 allocate(u1
, u2(2), SOURCE
= n1
)
72 allocate(u1
, u2(2), SOURCE
= new_line("a"))
73 allocate(n1
%whatever
, SOURCE
= n2(1))
74 allocate(p1
, p2(2), SOURCE
= p3
)
75 allocate(p3
%y
, p4(2)%y
, SOURCE
= B(5))
77 ! OK, not unlimited polymorphic or abstract