1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Check for semantic errors in ALLOCATE statements
4 subroutine C946(param_ca_4_assumed
, param_ta_4_assumed
, param_ca_4_deferred
)
5 ! If source-expr appears, the kind type parameters of each allocate-object shall
6 ! have the same values as the corresponding type parameters of source-expr.
8 real(kind
=4), allocatable
:: x1
, x2(:)
10 type WithParam(k1
, l1
)
16 type, extends(WithParam
) :: WithParamExtent(k2
, l2
)
21 type, extends(WithParamExtent
) :: WithParamExtent2(k3
, l3
)
22 integer, kind
:: k3
= 8
26 real(kind
=4) srcx
, srcx_array(10)
27 real(kind
=8) srcx8
, srcx8_array(10)
28 class(WithParam(4, 2)), allocatable
:: src_a_4_2
29 type(WithParam(8, 2)) src_a_8_2
30 class(WithParam(4, :)), allocatable
:: src_a_4_def
31 class(WithParam(8, :)), allocatable
:: src_a_8_def
32 type(WithParamExtent(4, 2, 8, 3)) src_b_4_2_8_3
33 class(WithParamExtent(4, :, 8, 3)), allocatable
:: src_b_4_def_8_3
34 type(WithParamExtent(8, 2, 8, 3)) src_b_8_2_8_3
35 class(WithParamExtent(8, :, 8, 3)), allocatable
:: src_b_8_def_8_3
36 type(WithParamExtent2(k1
=4, l1
=5, k2
=5, l2
=6, l3
=8 )) src_c_4_5_5_6_8_8
37 class(WithParamExtent2(k1
=4, l1
=2, k2
=5, l2
=6, k3
=5, l3
=8)), &
38 allocatable
:: src_c_4_2_5_6_5_8
39 class(WithParamExtent2(k2
=5, l2
=6, k3
=5, l3
=8)), &
40 allocatable
:: src_c_1_2_5_6_5_8
41 type(WithParamExtent2(k1
=5, l1
=5, k2
=5, l2
=6, l3
=8 )) src_c_5_5_5_6_8_8
42 type(WithParamExtent2(k1
=5, l1
=2, k2
=5, l2
=6, k3
=5, l3
=8)) src_c_5_2_5_6_5_8
45 type(WithParam(4, 2)), allocatable
:: param_ta_4_2
46 class(WithParam(4, 2)), pointer :: param_ca_4_2
48 type(WithParam(4, *)), pointer :: param_ta_4_assumed
49 class(WithParam(4, *)), allocatable
:: param_ca_4_assumed
51 type(WithParam(4, :)), allocatable
:: param_ta_4_deferred
52 class(WithParam(4, :)), pointer :: param_ca_4_deferred
53 class(WithParam
), allocatable
:: param_defaulted
54 integer, allocatable
:: integer_default(:)
56 type(WithParamExtent2(k1
=4, l1
=:, k2
=5, l2
=:, l3
=8 )), pointer :: extended2
58 class(*), pointer :: whatever
61 allocate(x1
, x2(10), source
=srcx
)
62 allocate(x2(10), source
=srcx_array
)
63 allocate(param_ta_4_2
, param_ca_4_2
, mold
=src_a_4_2
)
64 allocate(param_ca_4_2
, source
=src_b_4_2_8_3
)
65 allocate(param_ta_4_2
, param_ca_4_2
, mold
=src_a_4_def
) ! no C935 equivalent for source-expr
66 allocate(param_ca_4_2
, source
=src_b_4_def_8_3
) ! no C935 equivalent for source-expr
67 allocate(param_ta_4_assumed
, param_ca_4_assumed
, source
=src_a_4_def
)
68 allocate(param_ca_4_assumed
, mold
=src_b_4_def_8_3
)
69 allocate(param_ta_4_assumed
, param_ca_4_assumed
, source
=src_a_4_2
) ! no C935 equivalent for source-expr
70 allocate(param_ca_4_assumed
, mold
=src_b_4_2_8_3
) ! no C935 equivalent for source-expr
71 allocate(param_ta_4_deferred
, param_ca_4_deferred
, source
=src_a_4_2
)
72 allocate(param_ca_4_deferred
, mold
=src_b_4_def_8_3
)
74 allocate(extended2
, source
=src_c_4_5_5_6_8_8
)
75 allocate(param_ca_4_2
, mold
= src_c_4_2_5_6_5_8
)
76 allocate(param_defaulted
, mold
=WithParam(5))
77 allocate(param_defaulted
, source
=WithParam(k1
=1)(x
=5))
78 allocate(param_defaulted
, mold
=src_c_1_2_5_6_5_8
)
79 allocate(whatever
, source
=src_c_1_2_5_6_5_8
)
81 allocate(integer_default
, source
=[(i
,i
=0,9)])
84 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
85 allocate(x1
, source
=cos(0._8
))
86 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
87 allocate(x2(10), source
=srcx8
)
88 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
89 allocate(x2(10), mold
=srcx8_array
)
90 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
91 allocate(param_ta_4_2
, source
=src_a_8_2
)
92 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
93 allocate(param_ca_4_2
, mold
=src_a_8_2
)
94 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
95 allocate(param_ta_4_2
, source
=src_a_8_def
)
96 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
97 allocate(param_ca_4_2
, source
=src_b_8_2_8_3
)
98 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
99 allocate(param_ca_4_2
, mold
=src_b_8_def_8_3
)
100 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
101 allocate(param_ta_4_assumed
, source
=src_a_8_def
)
102 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
103 allocate(param_ta_4_assumed
, mold
=src_a_8_2
)
104 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
105 allocate(param_ca_4_assumed
, mold
=src_a_8_def
)
106 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
107 allocate(param_ca_4_assumed
, source
=src_b_8_2_8_3
)
108 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
109 allocate(param_ta_4_deferred
, mold
=src_a_8_2
)
110 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
111 allocate(param_ca_4_deferred
, source
=src_a_8_def
)
112 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
113 allocate(param_ca_4_deferred
, mold
=src_b_8_2_8_3
)
114 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
115 allocate(extended2
, source
=src_c_5_5_5_6_8_8
)
116 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
117 allocate(param_ca_4_2
, mold
=src_c_5_2_5_6_5_8
)
118 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
119 allocate(extended2
, source
=WithParamExtent2(k1
=4, l1
=5, k2
=5, l2
=6, k3
=5, l3
=8)(x
=5))
120 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
121 allocate(param_ca_4_2
, mold
=param_defaulted
)
122 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
123 allocate(param_defaulted
, source
=param_ca_4_2
)
124 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
125 allocate(param_defaulted
, mold
=WithParam(k1
=2)(x
=5))
126 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
127 allocate(param_defaulted
, source
=src_c_5_2_5_6_5_8
)
128 !ERROR: Kind type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression
129 allocate(integer_default
, source
=[(i
, integer(8)::i
=0,9)])