[Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter
kloedej at knmi dot nl
gcc-bugzilla@gcc.gnu.org
Mon Oct 6 11:33:00 GMT 2008
The following testcase of (I think) valid Fortran90 code, shows a strange
error. It copies all characters of a text string except for the first
character, which for some unknown reason is replaced by a space.
The essential element seems to be the use of the expression len(a)+1 to
dimension the size of string b.
subroutine copy(a,b)
character(len=*), intent(in) :: a
character(len=len(a)+1), intent(out) :: b
integer :: c
print *,"inside1: a = ["//trim(a)//"]"
b(:)=' '
c=len_trim(a)
b(1:c)=a(1:c)
print *,"inside2: a = ["//trim(a)//"]"
print *,"len_trim(a)=",c
print *,"inside: b = ["//trim(b)//"]"
end subroutine copy
program Test_StrCopy
character(len=50) :: a,b
a = "abcdefg"
call copy(a,b)
end program Test_StrCopy
After compiling with: gfortran -o Test_Copy Test_Copy.F90
I get this result:
>Test_Copy
inside1: a = [abcdefg]
inside2: a = [ bcdefg]
len_trim(a)= 7
inside: b = [ bcdefg]
>
Clearly, the problem seems to be that the intent(in) variable a gets modified,
which should never happen.
gfortran version used for testing was:
gfortran -v
Using built-in specs.
Target: i586-pc-linux-gnu
Configured with: /home/fx/gfortran_nightbuild/trunk/configure
--prefix=/home/fx/gfortran_nightbuild/irun-20081005
--enable-languages=c,fortran --build=i586-pc-linux-gnu
--enable-checking=release --with-gmp=/home/fx/gfortran_nightbuild/software
Thread model: posix
gcc version 4.4.0 20081005 (experimental) [trunk revision 140878] (GCC)
>
Best regards,
Jos de Kloe, KNMI
--
Summary: string copy fails, due to changed intent(in) parameter
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kloedej at knmi dot nl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37746
More information about the Gcc-bugs
mailing list