[Bug libfortran/78833] Misleading IOMSG after failed WRITE(...,POS=) on unconnected formatted stream file

2016-12-17 Thread jvdelisle at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78833

Jerry DeLisle  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||jvdelisle at gcc dot gnu.org
 Resolution|--- |INVALID

--- Comment #5 from Jerry DeLisle  ---
Yes, the bug is in your program. After failing to open the subsequent write
statements are assuming default open which is by definition, sequentiial, so
the error message is correct.

On the initial failure your program should not attempt any writes and probably
should gracefully exit.

[Bug libfortran/78833] Misleading IOMSG after failed WRITE(...,POS=) on unconnected formatted stream file

2016-12-17 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78833

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 CC||kargl at gcc dot gnu.org

--- Comment #4 from kargl at gcc dot gnu.org ---
(In reply to mecej4 from comment #3)
> I understand what happens, and this is not a bug per se', but in normal
> usage the message wording can be confusing.
> 
> During the second run, the OPEN fails because 'NEW' is specified and the
> file already exists.
> 
> If the program does not stop when the OPEN failed and goes on to the WRITE,
> the unit is not open or connected, so an implicit OPEN is performed to file
> 'FORT10', with no keyword options in the implicit OPEN. Therefore, the newly
> created FORT10 is not a stream file. but a simple formatted sequential file,
> and the WRITE fails because it contains a POS= clause. 
> 
> These details are not immediately evident when one looks at the WRITE
> statement, hence the possibility of confusion. Wording such as "'POS='
> clause in WRITE to sequential formatted file FORT10" would alert the user to
> what went wrong and how to resolve the problem.

Looks like a programming error on the part of a user.  If a
programmer requests the iostat of an OPEN, and then refuses
to act of the return value then the programmer gets want
the get.  Specifically your bug is here:

if(iok /= 0)write(*,*) 'IOSTAT after OPEN: ',IOK,' ',trim(msg)

A properly written program would do

if(iok /= 0)then
  write(*,*) 'IOSTAT after OPEN: ',IOK,' ',trim(msg)
  stop
end if

or 

if(iok /= 0)then
  write(*,*) 'IOSTAT after OPEN: ',IOK,' ',trim(msg)
  call do_something_clever_here.
end if

[Bug libfortran/78833] Misleading IOMSG after failed WRITE(...,POS=) on unconnected formatted stream file

2016-12-17 Thread mecej4 at operamail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78833

--- Comment #3 from mecej4 at operamail dot com ---
I understand what happens, and this is not a bug per se', but in normal usage
the message wording can be confusing.

During the second run, the OPEN fails because 'NEW' is specified and the file
already exists.

If the program does not stop when the OPEN failed and goes on to the WRITE, the
unit is not open or connected, so an implicit OPEN is performed to file
'FORT10', with no keyword options in the implicit OPEN. Therefore, the newly
created FORT10 is not a stream file. but a simple formatted sequential file,
and the WRITE fails because it contains a POS= clause. 

These details are not immediately evident when one looks at the WRITE
statement, hence the possibility of confusion. Wording such as "'POS=' clause
in WRITE to sequential formatted file FORT10" would alert the user to what went
wrong and how to resolve the problem.

[Bug libfortran/78833] Misleading IOMSG after failed WRITE(...,POS=) on unconnected formatted stream file

2016-12-16 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78833

Dominique d'Humieres  changed:

   What|Removed |Added

   Priority|P3  |P4
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-12-16
 Ever confirmed|0   |1
   Severity|normal  |enhancement

--- Comment #2 from Dominique d'Humieres  ---
Confirmed from 4.4 up to trunk (7.0). 4.3.1 and 4.3.6 gives

 IOSTAT after OPEN:   17  File 'strm.dat' already exists
 IOSTAT after WRITE: 5001  Record number not allowed for sequential
access data transfer

[Bug libfortran/78833] Misleading IOMSG after failed WRITE(...,POS=) on unconnected formatted stream file

2016-12-16 Thread mecej4 at operamail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78833

--- Comment #1 from mecej4 at operamail dot com ---
Created attachment 40349
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40349=edit
Test program for reproducing bug in IOMSG

Same source code as in main message, for your convenience.