Bug 45463 - gfortran internal write bug
Summary: gfortran internal write bug
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-31 12:50 UTC by David Sagan
Modified: 2010-09-01 02:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Sagan 2010-08-31 12:50:28 UTC
Consider the following code: 

program test 
implicit none 
character(40) line 
line = 'Hello World!' 
write (line, '(i3, 2x, a)') 7, trim(line) 
print *, line 
end program 

With the gfortran compiler (v4.5.1) the output is: 
   7    7lo World! 
I would expect the output to be
   7  Hello World! 

-- David
Comment 1 kargl 2010-08-31 13:28:45 UTC
Did you see the responses to your post in c.l.f?
It seems that your program is non-conforming.  I
leave the PR open until either I or someone else
has time to verify the conformity of the program.
Comment 2 David Sagan 2010-08-31 14:20:45 UTC
(In reply to comment #1)
> Did you see the responses to your post in c.l.f?
> It seems that your program is non-conforming.  I
> leave the PR open until either I or someone else
> has time to verify the conformity of the program.
> 

Sorry. When I looked after I had posted the question there was only one response and that response said it was a bug so I submitted this bug report. Now other people have posted saying that the program is non-conforming.
Comment 3 David Sagan 2010-08-31 14:32:19 UTC
(In reply to comment #2)
> Sorry. When I looked after I had posted the question there was only one
> response and that response said it was a bug so I submitted this bug report.
> Now other people have posted saying that the program is non-conforming.

Update: More responses in comp.lang.fortran bring up the point that if trim(line)
is supposed to return a temporary, the code might be conforming. Seems that the situation is not clear...
Comment 4 kargl 2010-08-31 16:40:49 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Sorry. When I looked after I had posted the question there was only one
> > response and that response said it was a bug so I submitted this bug report.
> > Now other people have posted saying that the program is non-conforming.
> 
> Update: More responses in comp.lang.fortran bring up the point that if
> trim(line)
> is supposed to return a temporary, the code might be conforming. Seems that the
> situation is not clear...

IMNSHO, it's not conforming.  trim(line) is associated with line.
I don't see how one could interpret the standard in in other way.

> 

Comment 5 kargl 2010-08-31 16:49:01 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #2)
> > > Sorry. When I looked after I had posted the question there was only one
> > > response and that response said it was a bug so I submitted this bug report.
> > > Now other people have posted saying that the program is non-conforming.
> > 
> > Update: More responses in comp.lang.fortran bring up the point that if
> > trim(line)
> > is supposed to return a temporary, the code might be conforming. Seems that the
> > situation is not clear...
> 
> IMNSHO, it's not conforming.  trim(line) is associated with line.
> I don't see how one could interpret the standard in in other way.
> 
> > 

In fact, 16.5.7 in F2003, is fairly unambiguous.  The code is
nonconforming.

Comment 6 Jerry DeLisle 2010-09-01 02:10:51 UTC
> Update: More responses in comp.lang.fortran bring up the point that if
> trim(line)
> is supposed to return a temporary, the code might be conforming. Seems that the
> situation is not clear...

Where in the standard does it say that trim(line) must generate a temporary.  I can think of an implementation that would track the length trimmed to and conserve the memory.  My point being that this level of behavior, using temporaries or not, IMNSHO, is implementation detail that does not belong in the standard if it is there. c.l.f folks sometimes get a bit esoteric in their discussions.

I am closing this bug as not a bug (invalid). I do appreciate the report though.  We do not want to miss things and its better to error on the safe side and report then not.