xref: /llvm-project/flang/test/Semantics/allocate02.f90 (revision 6c1ac141d3c98af9738bc77fcb55602cbff7751f)
1! RUN: %python %S/test_errors.py %s %flang_fc1
2
3! Check for semantic errors in ALLOCATE statements
4
5subroutine C943_C944(src, src2)
6! C943
7! No alloc-opt shall appear more than once in a given alloc-opt-list.
8  character(50) msg
9  integer stat, stat2
10  real src(2:4), src2(2:4)
11  real mld(2:4), mld2(2:4)
12  real, allocatable :: x1(:), x2(:), x3(:), x4(:), x5(:), x6(:), x7(:), x8(:), x9(:)
13  real, allocatable :: y1(:), y2(:), y3(:), y4(:)
14  real, pointer :: p1, p2
15
16  !Nominal cases, no error expected
17  allocate(x1, source=src)
18  allocate(x2, mold=mld)
19  allocate(x3(2:4), stat=stat)
20  allocate(x4(2:4), stat=stat, errmsg=msg)
21  allocate(x5(2:4), source=src, stat=stat, errmsg=msg)
22
23  !ERROR: STAT may not be duplicated in a ALLOCATE statement
24  allocate(x6, stat=stat, source=src, stat=stat2)
25
26  !ERROR: SOURCE may not be duplicated in a ALLOCATE statement
27  allocate(x7, source=src, stat=stat, source=src2)
28
29  !ERROR: MOLD may not be duplicated in a ALLOCATE statement
30  allocate(x8, mold=mld, stat=stat, mold=mld)
31
32  !ERROR: ERRMSG may not be duplicated in a ALLOCATE statement
33  allocate(x9, mold=mld, errmsg=msg, stat=stat, errmsg= msg)
34
35! C944
36! At most one of source-expr and type-spec must appear.
37
38  !Nominal cases already tested in C943 and type-spec tests (e.g C934)
39
40  !ERROR: At most one of source-expr and type-spec may appear in a ALLOCATE statement
41  allocate(real:: y1, source=src)
42  !ERROR: At most one of source-expr and type-spec may appear in a ALLOCATE statement
43  allocate(real:: y2, mold=mld)
44  !ERROR: At most one of source-expr and type-spec may appear in a ALLOCATE statement
45  allocate(y3, source=src, stat=stat, errmsg=msg, mold=mld)
46  !ERROR: At most one of source-expr and type-spec may appear in a ALLOCATE statement
47  allocate(real:: y4, source=src, stat=stat, errmsg=msg, mold=mld)
48end subroutine
49