141 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic2! Check for semantic errors in ALLOCATE statements3 4subroutine 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 shall6! have the same values as the corresponding type parameters of source-expr.7 8 real(kind=4), allocatable :: x1, x2(:)9 10 type WithParam(k1, l1)11 integer, kind :: k1=112 integer, len :: l1=213 real x14 end type15 16 type, extends(WithParam) :: WithParamExtent(k2, l2)17 integer, kind :: k218 integer, len :: l219 end type20 21 type, extends(WithParamExtent) :: WithParamExtent2(k3, l3)22 integer, kind :: k3 = 823 integer, len :: l324 end type25 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_229 type(WithParam(8, 2)) src_a_8_230 class(WithParam(4, :)), allocatable :: src_a_4_def31 class(WithParam(8, :)), allocatable :: src_a_8_def32 type(WithParamExtent(4, 2, 8, 3)) src_b_4_2_8_333 class(WithParamExtent(4, :, 8, 3)), allocatable :: src_b_4_def_8_334 type(WithParamExtent(8, 2, 8, 3)) src_b_8_2_8_335 class(WithParamExtent(8, :, 8, 3)), allocatable :: src_b_8_def_8_336 type(WithParamExtent2(k1=4, l1=5, k2=5, l2=6, l3=8 )) src_c_4_5_5_6_8_837 class(WithParamExtent2(k1=4, l1=2, k2=5, l2=6, k3=5, l3=8)), &38 allocatable :: src_c_4_2_5_6_5_839 class(WithParamExtent2(k2=5, l2=6, k3=5, l3=8)), &40 allocatable :: src_c_1_2_5_6_5_841 type(WithParamExtent2(k1=5, l1=5, k2=5, l2=6, l3=8 )) src_c_5_5_5_6_8_842 type(WithParamExtent2(k1=5, l1=2, k2=5, l2=6, k3=5, l3=8)) src_c_5_2_5_6_5_843 44 45 type(WithParam(4, 2)), allocatable :: param_ta_4_246 class(WithParam(4, 2)), pointer :: param_ca_4_247 48 type(WithParam(4, *)), pointer :: param_ta_4_assumed49 class(WithParam(4, *)), allocatable :: param_ca_4_assumed50 51 type(WithParam(4, :)), allocatable :: param_ta_4_deferred52 class(WithParam(4, :)), pointer :: param_ca_4_deferred53 class(WithParam), allocatable :: param_defaulted54 integer, allocatable :: integer_default(:)55 56 type(WithParamExtent2(k1=4, l1=:, k2=5, l2=:, l3=8 )), pointer :: extended257 58 class(*), pointer :: whatever59 60 character(:), allocatable :: deferredChar61 character(2), allocatable :: char262 63 ! Nominal test cases64 allocate(x1, x2(10), source=srcx)65 allocate(x2(10), source=srcx_array)66 allocate(param_ta_4_2, param_ca_4_2, mold=src_a_4_2)67 allocate(param_ca_4_2, source=src_b_4_2_8_3)68 allocate(param_ta_4_2, param_ca_4_2, mold=src_a_4_def) ! no C935 equivalent for source-expr69 allocate(param_ca_4_2, source=src_b_4_def_8_3) ! no C935 equivalent for source-expr70 allocate(param_ta_4_assumed, param_ca_4_assumed, source=src_a_4_def)71 allocate(param_ca_4_assumed, mold=src_b_4_def_8_3)72 allocate(param_ta_4_assumed, param_ca_4_assumed, source=src_a_4_2) ! no C935 equivalent for source-expr73 allocate(param_ca_4_assumed, mold=src_b_4_2_8_3) ! no C935 equivalent for source-expr74 allocate(param_ta_4_deferred, param_ca_4_deferred, source =src_a_4_2)75 allocate(param_ca_4_deferred, mold=src_b_4_def_8_3)76 77 allocate(extended2, source=src_c_4_5_5_6_8_8)78 allocate(param_ca_4_2, mold= src_c_4_2_5_6_5_8)79 allocate(param_defaulted, mold=WithParam(5))80 allocate(param_defaulted, source=WithParam(k1=1)(x=5))81 allocate(param_defaulted, mold=src_c_1_2_5_6_5_8)82 allocate(whatever, source=src_c_1_2_5_6_5_8)83 84 allocate(integer_default, source=[(i,i=0,9)])85 86 allocate(deferredChar, source="abcd")87 allocate(deferredChar, mold=deferredChar)88 !PORTABILITY: Character length of allocatable object in ALLOCATE should be the same as the SOURCE or MOLD [-Wallocate-to-other-length]89 allocate(char2, source="a")90 !PORTABILITY: Character length of allocatable object in ALLOCATE should be the same as the SOURCE or MOLD [-Wallocate-to-other-length]91 allocate(char2, source="abc")92 allocate(char2, mold=deferredChar)93 94 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression95 allocate(x1, source=cos(0._8))96 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression97 allocate(x2(10), source=srcx8)98 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression99 allocate(x2(10), mold=srcx8_array)100 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression101 allocate(param_ta_4_2, source=src_a_8_2)102 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression103 allocate(param_ca_4_2, mold=src_a_8_2)104 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression105 allocate(param_ta_4_2, source=src_a_8_def)106 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression107 allocate(param_ca_4_2, source=src_b_8_2_8_3)108 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression109 allocate(param_ca_4_2, mold=src_b_8_def_8_3)110 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression111 allocate(param_ta_4_assumed, source=src_a_8_def)112 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression113 allocate(param_ta_4_assumed, mold=src_a_8_2)114 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression115 allocate(param_ca_4_assumed, mold=src_a_8_def)116 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression117 allocate(param_ca_4_assumed, source=src_b_8_2_8_3)118 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression119 allocate(param_ta_4_deferred, mold=src_a_8_2)120 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression121 allocate(param_ca_4_deferred, source=src_a_8_def)122 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression123 allocate(param_ca_4_deferred, mold=src_b_8_2_8_3)124 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression125 allocate(extended2, source=src_c_5_5_5_6_8_8)126 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression127 allocate(param_ca_4_2, mold=src_c_5_2_5_6_5_8)128 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression129 allocate(extended2, source=WithParamExtent2(k1=4, l1=5, k2=5, l2=6, k3=5, l3=8)(x=5))130 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression131 allocate(param_ca_4_2, mold=param_defaulted)132 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression133 allocate(param_defaulted, source=param_ca_4_2)134 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression135 allocate(param_defaulted, mold=WithParam(k1=2)(x=5))136 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression137 allocate(param_defaulted, source=src_c_5_2_5_6_5_8)138 !ERROR: Derived type parameters of allocatable object must be the same as the corresponding ones of SOURCE or MOLD expression139 allocate(integer_default, source=[(i, integer(8)::i=0,9)])140end subroutine141