80 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Check for semantic errors in ALLOCATE statements3 4 5subroutine C933_b(n)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 unlimited polymorphic and abstract-type here10 11 type, abstract :: Base12 integer x13 end type14 15 type, extends(Base) :: A16 integer y17 end type18 19 type, extends(Base) :: B20 class(Base), allocatable :: y21 end type22 23 type C24 class(*), pointer :: whatever25 real, pointer :: y26 end type27 28 integer n29 class(*), allocatable :: u1, u2(:)30 class(C), allocatable :: n1, n2(:)31 class(Base), pointer :: p1, p2(:)32 class(B), pointer :: p3, p4(:)33 type(A) :: molda = A(1, 2)34 35 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is unlimited polymorphic36 allocate(u1)37 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is unlimited polymorphic38 allocate(u2(2))39 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is unlimited polymorphic40 allocate(n1%whatever)41 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is unlimited polymorphic42 allocate(n2(2)%whatever)43 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is of abstract type44 allocate(p1)45 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is of abstract type46 allocate(p2(2))47 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is of abstract type48 allocate(p3%y)49 !ERROR: Either type-spec or source-expr must appear in ALLOCATE when allocatable object is of abstract type50 allocate(p4(2)%y)51 !WRONG allocate(Base:: u1)52 53 ! No error expected54 allocate(real:: u1, u2(2))55 allocate(A:: u1, u2(2))56 allocate(C:: u1, u2(2))57 allocate(character(n):: u1, u2(2))58 allocate(C:: n1%whatever, n2(2)%whatever)59 allocate(A:: p1, p2(2))60 allocate(B:: p3%y, p4(2)%y)61 allocate(u1, u2(2), MOLD = cos(5.+n))62 allocate(u1, u2(2), MOLD = molda)63 allocate(u1, u2(2), MOLD = n1)64 allocate(u1, u2(2), MOLD = new_line(a="a"))65 allocate(n1%whatever, MOLD = n2(1))66 allocate(p1, p2(2), MOLD = p3)67 allocate(p3%y, p4(2)%y, MOLD = B(5))68 allocate(u1, u2(2), SOURCE = cos(5.+n))69 allocate(u1, u2(2), SOURCE = molda)70 allocate(u1, u2(2), SOURCE = n1)71 allocate(u1, u2(2), SOURCE = new_line("a"))72 allocate(n1%whatever, SOURCE = n2(1))73 allocate(p1, p2(2), SOURCE = p3)74 allocate(p3%y, p4(2)%y, SOURCE = B(5))75 76 ! OK, not unlimited polymorphic or abstract77 allocate(n1, n2(2))78 allocate(p3, p4(2))79end subroutine80