124 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Check for semantic errors in ALLOCATE statements3 4subroutine C941_C942b_C950(xsrc, x1, a2, b2, cx1, ca2, cb1, cb2, c1, c2)5! C941: An allocate-coarray-spec shall appear if and only if the allocate-object6! is a coarray.7 type type08 real, allocatable :: array(:)9 end type10 type type111 class(type0), pointer :: t012 end type13 14 type type215 type(type1), pointer :: t1(:)16 end type17 18 type A19 real x(10)20 end type21 22 type B23 real, allocatable :: x(:)24 end type25 26 type C27 class(type2), allocatable :: ct2(:, :)[:, :, :]28 class(A), allocatable :: cx(:, :)[:, :, :]29 class(A), allocatable :: x(:, :)30 end type31 32 real :: xsrc(10)33 real, allocatable :: x1, x2(:)34 class(A), pointer :: a1, a2(:)35 36 real, allocatable :: cx1[:], cx2(:)[:, :]37 class(A), allocatable :: ca1[:, :], ca2(:)[:]38 39 type(B) :: b1, b2(*)40 type(B) :: cb1[5:*], cb2(*)[2, -1:*]41 42 type(C) :: c143 pointer :: c2(:, :)44 pointer :: varLocal(:)45 46 class(*), allocatable :: var(:), cvar(:)[:]47 48 ! Valid constructs49 allocate(x1, x2(10), cx1[*], cx2(10)[2, -1:*])50 allocate(a1, a2(10), ca1[2, -1:*], ca2(10)[*])51 allocate(b1%x, b2(1)%x, cb1%x, cb2(1)%x, SOURCE=xsrc)52 allocate(c1%x(-1:10, 1:5), c1%cx(-1:10, 1:5)[-1:5, 1:2, 2:*])53 allocate(c2(9, 27))54 allocate(varLocal(64))55 allocate(A:: var(5), cvar(10)[*])56 57 58 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray59 allocate(x1[*])60 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray61 allocate(x2(10)[*])62 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray63 allocate(cx1)64 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray65 allocate(cx2(10))66 67 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray68 allocate(cx1[*], a1[*])69 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray70 allocate(cx1[*], a2(10)[*])71 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray72 allocate(x1, ca1)73 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray74 allocate(ca1[2, -1:*], ca2(10))75 76 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray77 allocate(b1%x[5:*] , SOURCE=xsrc)78 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray79 allocate(b2(1)%x[2, -1:*], SOURCE=xsrc)80 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray81 allocate(cb1%x[5:*] , SOURCE=xsrc)82 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray83 allocate(cb2(1)%x[2, -1:*], SOURCE=xsrc)84 85 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray86 allocate(c1%x(-1:10, 1:5)[-1:5, 1:2, 2:*])87 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray88 allocate(c1%cx(-1:10, 1:5))89 90 !ERROR: Coarray specification must not appear in ALLOCATE when allocatable object is not a coarray91 allocate(A:: var(5)[*], cvar(10)[*])92 !ERROR: Coarray specification must appear in ALLOCATE when allocatable object is a coarray93 allocate(A:: var(5), cvar(10))94 95! C942b: [... (shape related stuff not tested here) ...]. The number of96! allocate-coshape-specs in an allocate-coarray-spec shall be one less97! than the corank of the allocate-object.98 99 ! Valid constructs already tested above100 101 !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray102 allocate(cx1[2,-1:*], cx2(10)[2, -1:*])103 !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray104 allocate(ca1[*], ca2(10)[*])105 !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray106 allocate(c1%cx(-1:10, 1:5)[-1:5, 1:*])107 !ERROR: Corank of coarray specification in ALLOCATE must match corank of alloctable coarray108 allocate(A:: cvar(10)[2,2,*])109 110! C950: An allocate-object shall not be a coindexed object.111 112 ! Valid construct113 allocate(c1%ct2(2,5)%t1(2)%t0%array(10))114 115 !ERROR: cosubscript 2 is less than lower cobound 5 for codimension 1 of array116 !ERROR: Allocatable object must not be coindexed in ALLOCATE117 allocate(b1%x, b2(1)%x, cb1[2]%x, SOURCE=xsrc)118 !ERROR: Allocatable object must not be coindexed in ALLOCATE119 allocate(b1%x, b2(1)%x, cb2(1)[2,-1]%x, MOLD=xsrc)120 !ERROR: Allocatable object must not be coindexed in ALLOCATE121 allocate(c1%ct2(2,5)[1,1,1]%t1(2)%t0%array(10))122 123end subroutine124