[Bug fortran/83224] New: creating character array from elements shorter than declared does not pad with whitespace properly and aborts
urbanjost at comcast dot net
gcc-bugzilla@gcc.gnu.org
Thu Nov 30 06:22:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83224
Bug ID: 83224
Summary: creating character array from elements shorter than
declared does not pad with whitespace properly and
aborts
Product: gcc
Version: 6.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: urbanjost at comcast dot net
Target Milestone: ---
I expect this program to produce at the end
============================================================
PASS 21
[one ][two ][three ][four ][five ]
[six ][seven ][eight ][nine ][ten[ ]
[eleven ][twelve ][thirteen ][fourteen ][fifteen ]
[sixteen ][seventeen][eighteen ][nineteen ][twenty ]
[twentyone]
============================================================
Instead, I got an abort when the length reached 9 characters, and without
the blank padding I was expecting ....
============================================================
PASS 16
[onetwttw][twothtth][threeffo][four ffi][five ssi]
[six sse][seveneei][eightnni][nine tte][ten eel]
[eleventw][twelveth][thirteen][fourteen][fifteen ]
[sixteen ]
============================================================
Program received signal SIGABRT: Process abort signal.
I am using gfortran 6.4 on Cygwin, and it was confirmed that it
acts as I thought it would with another Fortran implementation
(Intel 18.0.1).
program dusty_corner ! exercise f2008 CHARACTER features
implicit none
character(len=:),allocatable :: words(:)
character(len=:),allocatable :: trimmed
integer :: i,big
character(len=*),parameter :: data(*)=[character(len=20) :: &
'one', 'two', 'three', 'four', 'five', &
'six', 'seven', 'eight', 'nine', 'ten' , &
'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', &
'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', &
'twentyone' ]
words=[character(len=0)::] ! Allocate zero-size array
big=0
INFINITE: do i=1,size(data)
trimmed=trim(data(i)) ! create variables of various lengths
big=max(big,len(trimmed)) ! find longest length so far
! next, when BIG increases WORDS should be padded with spaces?
words=[ CHARACTER(LEN=big) :: words, trimmed ]
write(*,'(a,i0)')'PASS ',i
write(*,'(5("[",a,"]":))')words
write(*,'(a)')repeat('=',80)
enddo INFINITE
end program dusty_corner
More information about the Gcc-bugs
mailing list