1! RUN: %S/test_errors.sh %s %t %flang_fc1
2! REQUIRES: shell
3! Check for semantic errors in ALLOCATE statements
4
5subroutine 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.
8
9! Only testing deferred type parameters here.
10
11  type SomeType(k, l1, l2)
12    integer, kind :: k = 1
13    integer, len :: l1
14    integer, len :: l2 = 3
15    character(len=l2+l1) str
16  end type
17
18  type B(l)
19    integer, len :: l
20    character(:), allocatable :: msg
21    type(SomeType(4, l, :)), pointer :: something
22  end type
23
24  character(len=:), allocatable :: ca1, ca2(:)
25  character(len=*), allocatable :: ca3, ca4(:)
26  character(len=2), allocatable :: ca5, ca6(:)
27  character(len=5) mold
28
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(:)
37
38  type(B(*)) b1
39  type(B(:)), allocatable :: b2
40  type(B(5)) b3
41
42  type(SomeType(4, *, 8)) bsrc
43
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
46  allocate(ca1)
47  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
48  allocate(ca2(4))
49  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
50  allocate(cp1)
51  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
52  allocate(cp2(2))
53  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
54  allocate(cp3)
55  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
56  allocate(cp4(2))
57  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
58  allocate(cp5)
59  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
60  allocate(cp6(2))
61  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
62  allocate(b1%msg)
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
66  allocate(b2%msg)
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
70  allocate(b3%msg)
71  !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object has a deferred type parameters
72  allocate(b3%something)
73
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)
97
98  ! assumed/explicit length do not need type-spec/mold
99  allocate(ca3, ca4(4))
100  allocate(ca5, ca6(4))
101  allocate(cp7, cp8(2))
102  allocate(cp9, cp10(2))
103
104end subroutine
105