| 1 |
! { dg-do compile } |
| 2 |
! { dg-options "-std=f2008" } |
| 3 |
! PR fortran/113793 |
| 4 |
! |
| 5 |
! Static checks of string length for ALLOCATE with SOURCE= or MOLD= |
| 6 |
|
| 7 |
program p |
| 8 |
implicit none |
| 9 |
character(kind=1,len=8), allocatable :: a(:), d, b(:,:) |
| 10 |
character(kind=4,len=6), allocatable :: c(:), e, f(:,:) |
| 11 |
character(kind=1,len=2) :: c1 = "xx" |
| 12 |
character(kind=1,len=8) :: c2 = "yy" |
| 13 |
character(kind=4,len=6) :: c3 = 4_"ww" |
| 14 |
character(kind=4,len=3) :: c4 = 4_"zz" |
| 15 |
|
| 16 |
ALLOCATE (a(1),source= "a") ! { dg-error "Unequal character lengths .8/1. " } |
| 17 |
ALLOCATE (a(2),mold = "bb") ! { dg-error "Unequal character lengths .8/2. " } |
| 18 |
ALLOCATE (c(3),source=4_"yyy") ! { dg-error "Unequal character lengths .6/3. " } |
| 19 |
ALLOCATE (c(4),mold =4_"zzzz") ! { dg-error "Unequal character lengths .6/4. " } |
| 20 |
ALLOCATE (d, source= "12345") ! { dg-error "Unequal character lengths .8/5. " } |
| 21 |
ALLOCATE (d, source= "12345678") |
| 22 |
ALLOCATE (d, mold = "123456") ! { dg-error "Unequal character lengths .8/6. " } |
| 23 |
ALLOCATE (e, source=4_"654321") |
| 24 |
ALLOCATE (e, mold =4_"7654321") ! { dg-error "Unequal character lengths .6/7. " } |
| 25 |
ALLOCATE (a(5),source=c1) ! { dg-error "Unequal character lengths .8/2. " } |
| 26 |
ALLOCATE (a(6),mold =c1) ! { dg-error "Unequal character lengths .8/2. " } |
| 27 |
ALLOCATE (c(7),source=c4) ! { dg-error "Unequal character lengths .6/3. " } |
| 28 |
ALLOCATE (c(8),mold =c4) ! { dg-error "Unequal character lengths .6/3. " } |
| 29 |
ALLOCATE (a,source=[c1,c1,c1]) ! { dg-error "Unequal character lengths .8/2. " } |
| 30 |
ALLOCATE (a,source=[c2,c2,c2]) |
| 31 |
ALLOCATE (c,source=[c3,c3]) |
| 32 |
ALLOCATE (c,source=[c4,c4]) ! { dg-error "Unequal character lengths .6/3. " } |
| 33 |
ALLOCATE (d,source=c1) ! { dg-error "Unequal character lengths .8/2. " } |
| 34 |
ALLOCATE (e,source=c4) ! { dg-error "Unequal character lengths .6/3. " } |
| 35 |
ALLOCATE (b,source=reshape([c1],[1,1])) ! { dg-error "Unequal character lengths .8/2. " } |
| 36 |
ALLOCATE (b,source=reshape([c2],[1,1])) |
| 37 |
ALLOCATE (f,source=reshape([c3],[1,1])) |
| 38 |
ALLOCATE (f,source=reshape([c4],[1,1])) ! { dg-error "Unequal character lengths .6/3. " } |
| 39 |
contains |
| 40 |
subroutine foo (s) |
| 41 |
character(*), intent(in) :: s |
| 42 |
character(len=8), allocatable :: f(:), g |
| 43 |
ALLOCATE (f(3), source=s) |
| 44 |
ALLOCATE (d, source=s) |
| 45 |
ALLOCATE (f(3), mold=s) |
| 46 |
ALLOCATE (d, mold=s) |
| 47 |
end |
| 48 |
end |