| 1 |
! { dg-do run } |
| 2 |
! PR fortran/103115 - character array constructor with >= 4 constant elements |
| 3 |
! |
| 4 |
! This used to ICE when the first element is deferred-length character |
| 5 |
! or could lead to wrong results. |
| 6 |
|
| 7 |
program pr103115 |
| 8 |
implicit none |
| 9 |
integer :: i |
| 10 |
character(*), parameter :: expect(*) = [ "1","2","3","4","5" ] |
| 11 |
character(5) :: abc = "12345" |
| 12 |
character(5), parameter :: def = "12345" |
| 13 |
character(:), dimension(:), allocatable :: list |
| 14 |
character(:), dimension(:), allocatable :: titles |
| 15 |
titles = ["1"] |
| 16 |
titles = [ titles& |
| 17 |
,"2"& |
| 18 |
,"3"& |
| 19 |
,"4"& |
| 20 |
,"5"& ! used to ICE |
| 21 |
] |
| 22 |
if (len (titles) /= 1 .or. size (titles) /= 5) stop 1 |
| 23 |
if (any (titles /= expect)) stop 2 |
| 24 |
titles = ["1"] |
| 25 |
titles = [ titles, (char(48+i),i=2,5) ] |
| 26 |
if (len (titles) /= 1 .or. size (titles) /= 5) stop 3 |
| 27 |
if (any (titles /= expect)) stop 4 |
| 28 |
titles = ["1"] |
| 29 |
titles = [ titles, ("2345"(i:i),i=1,4) ] |
| 30 |
if (len (titles) /= 1 .or. size (titles) /= 5) stop 5 |
| 31 |
if (any (titles /= expect)) stop 6 |
| 32 |
titles = ["1"] |
| 33 |
titles = [ titles, (def(i:i),i=2,5) ] |
| 34 |
if (len (titles) /= 1 .or. size (titles) /= 5) stop 7 |
| 35 |
if (any (titles /= expect)) stop 8 |
| 36 |
list = [ (char(48+i),i=1,5) ] |
| 37 |
titles = [ list(1), (char(48+i),i=2,5) ] |
| 38 |
if (len (titles) /= 1 .or. size (titles) /= 5) stop 9 |
| 39 |
if (any (titles /= expect)) stop 10 |
| 40 |
titles = ["1"] |
| 41 |
titles = [ titles, (abc(i:i),i=2,5) ] |
| 42 |
if (len (titles) /= 1 .or. size (titles) /= 5) stop 11 |
| 43 |
if (any (titles /= expect)) stop 12 |
| 44 |
|
| 45 |
! with typespec: |
| 46 |
list = [ (char(48+i),i=1,5) ] |
| 47 |
titles = [ character(2) :: list(1), (char(48+i),i=2,5) ] |
| 48 |
if (len (titles) /= 2 .or. size (titles) /= 5) stop 13 |
| 49 |
if (any (titles /= expect)) stop 14 |
| 50 |
titles = ["1"] |
| 51 |
titles = [ character(2) :: titles, (char(48+i),i=2,5) ] |
| 52 |
if (len (titles) /= 2 .or. size (titles) /= 5) stop 15 |
| 53 |
if (any (titles /= expect)) stop 16 |
| 54 |
titles = ["1"] |
| 55 |
titles = [ character(2) :: titles, (def(i:i),i=2,5) ] |
| 56 |
if (len (titles) /= 2 .or. size (titles) /= 5) stop 17 |
| 57 |
if (any (titles /= expect)) stop 18 |
| 58 |
deallocate (titles, list) |
| 59 |
end |