[Bug fortran/31867] New: function result with character LEN computed at run time

beliavsky at aol dot com gcc-bugzilla@gcc.gnu.org
Tue May 8 15:28:00 GMT 2007

The program

module util_mod
implicit none
function join(words,sep) result(str)
! trim and concatenate a vector of character variables, 
! inserting sep between them
character (len=*), intent(in)        :: words(:),sep
character (len=(size(words)-1)*len(sep) + sum(len_trim(words))) :: str
integer                              :: i,nw
nw  = size(words)
str = ""
if (nw < 1) then
   str = words(1)
end if
do i=2,nw
   str = trim(str) // sep // words(i)
end do
end function join
end module util_mod
program xjoin
use util_mod, only: join
implicit none
character (len=5) :: words(2) = (/"two  ","three"/) 
write (*,"(1x,'words = ',a)") "'"//join(words," ")//"'"
end program xjoin


 words = 'two threeg9'

but I think it should give

 words = 'two three'

gfortran -v says

Using built-in specs.
Target: i386-pc-mingw32
Configured with: ../trunk/configure --prefix=/mingw
--enable-languages=c,fortran,c++,objc,obj-c++ --with-gmp=/home/coudert/local
--disable-nls --with-ld=/mingw/bin/ld --with-as=/mingw/bin/as --disable-werror
--enable-bootstrap --enable-threads --build=i386-pc-mingw32 --disable-shared
Thread model: win32
gcc version 4.3.0 20070406 (experimental)

           Summary: function result with character LEN computed at run time
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: beliavsky at aol dot com


More information about the Gcc-bugs mailing list