public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/37746]  New: string copy fails, due to changed intent(in) parameter
@ 2008-10-06 11:33 kloedej at knmi dot nl
  2008-10-06 14:48 ` [Bug fortran/37746] " kargl at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: kloedej at knmi dot nl @ 2008-10-06 11:33 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-04-11 16:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-06 11:33 [Bug fortran/37746] New: string copy fails, due to changed intent(in) parameter kloedej at knmi dot nl
2008-10-06 14:48 ` [Bug fortran/37746] " kargl at gcc dot gnu dot org
2008-10-06 19:54 ` burnus at gcc dot gnu dot org
2008-10-07 11:25 ` kloedej at knmi dot nl
2008-10-12 11:35 ` [Bug fortran/37746] bounds check of string dummy arguments tkoenig at gcc dot gnu dot org
2008-12-20 19:11 ` domob at gcc dot gnu dot org
2009-01-04  8:41 ` domob at gcc dot gnu dot org
2009-01-04  8:42 ` domob at gcc dot gnu dot org
2009-04-11 16:45 ` domob at gcc dot gnu dot org
2009-04-11 16:47 ` domob at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).