------- Comment #6 from Tobias dot Schlueter at physik dot uni-muenchen dot de 2007-10-11 10:45 ------- Subject: Re: Diagnose different string lengths in array constructors at run time
dominiq at lps dot ens dot fr wrote: > program array_char > implicit none > character (len=2) :: x, y > character (len=2) :: z(2) > x = "a " > y = "cd" > z = (/y(1:len(trim(y))), x(1:len(trim(x)))/) ! causes segfault > print *, "'", z(1), "' '", z(2), "'" > end program array_char > > gives > > [karma] f90/bug% gfc -fbounds-check pr33727_bad.f90 > [karma] f90/bug% a.out > 'cd' 'a' > > I am expecting this test to fail at runtime and the other one. Am I missing > something. This is weird, and can't really be (well, in a hypothetical world where only the bounds check goes wrong), as the whole array has only a single string length, so I would expect it to either print two length one strings or two length two strings, not one lenghth one string and one length two string. > > I have also noticed something strange with the following valid(?) code: > > program array_char > implicit none > character (len=2) :: x, y > character (len=2) :: z(2) > x = "a " > y = "cd" > z = " " > z = (/y(1:len(trim(x))), x(1:len(trim(x)))/) > print *, "'", z(1), "' '", z(2), "'" > end program array_char > > which gives > > 'c' 'a' > > while I am expecting > > 'c ' 'a ' > > Looks like another bug, should I fill a new PR? Yes. This looks related to the previous one, again the string length seems to be taken from the wrong place. Are these with or without Paul's patch? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33254