Bug 24945 - calling two open statements (same unit) without close fails
Summary: calling two open statements (same unit) without close fails
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 25036 (view as bug list)
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2005-11-19 19:22 UTC by milan
Modified: 2005-12-12 20:15 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-11-19 22:32:17


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description milan 2005-11-19 19:22:18 UTC
I am trying to open the same file twice. This works in g77, but fails in gfortran-4.1-20051112 snapshot

This is the program:
      integer iun,irecl
      iun=1
      irecl=5
      open(unit=iun,file='uu',status='unknown',access='direct',
     $     form='unformatted',recl=8*irecl)
C      close(unit=iun)
      open(unit=iun,file='uu',status='unknown',access='direct',
     $     form='unformatted',recl=8*irecl)
      end

If I use close it works, but as you can guess this is a part of larger program so I don't want to know where to put this close statement!
Comment 1 Francois-Xavier Coudert 2005-11-19 22:32:17 UTC
Confirmed (though I don't know why it should work and how it should behave). Intel accepts this too.
Comment 2 kargl 2005-11-20 01:16:21 UTC
See 9.3.4 from the standard.

If a unit is connected to a file that exists, execution of an OPEN statement
for that unit is permitted.  If the FILE= specifier is not included in such
an OPEN statement, the file to be connected to the unit is the same as the
file to which the unit is already connected.

If the file to be connected to the unit does not exist but is the same as
the file to which the unit is preconnected, the properties specified by
an OPEN statement become a part of the connection.

If the file to be connected to the unit is not the same as the file to
which the unit is connected, the effect is as if a CLOSE statement without
a STATUS= specifier had been executed for the unit immediately prior to th
execution of an OPEN statement.
Comment 3 Janne Blomqvist 2005-11-26 08:52:04 UTC
*** Bug 25036 has been marked as a duplicate of this bug. ***
Comment 4 Janne Blomqvist 2005-11-26 09:12:43 UTC
Subject: Bug 24945

Author: jb
Date: Sat Nov 26 09:12:36 2005
New Revision: 107538

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107538
Log:
libgfortran ChangeLog:

2005-11-26  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libgfortran/24945
	* io/open.c (edit_modes): Check for STATUS_UNKNOWN flag.
	
testsuite ChangeLog

2005-11-26  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libgfortran/24945
	* gfortran.dg/open_status_2.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/open_status_2.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/open.c

Comment 5 Janne Blomqvist 2005-11-26 09:27:26 UTC
Subject: Bug 24945

Author: jb
Date: Sat Nov 26 09:27:22 2005
New Revision: 107539

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107539
Log:
libgfortran ChangeLog:

2005-11-26  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libgfortran/24945
	* io/open.c (edit_modes): Check for STATUS_UNKNOWN flag.
	
testsuite ChangeLog

2005-11-26  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libgfortran/24945
	* gfortran.dg/open_status_2.f90: New test.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/open_status_2.f90
      - copied, changed from r107538, trunk/gcc/testsuite/gfortran.dg/open_status_2.f90
Modified:
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/libgfortran/ChangeLog
    branches/gcc-4_1-branch/libgfortran/io/open.c

Comment 6 Janne Blomqvist 2005-11-26 09:32:26 UTC
Subject: Bug 24945

Author: jb
Date: Sat Nov 26 09:32:21 2005
New Revision: 107540

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107540
Log:
testsuite ChangeLog:

2005-11-26  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libgfortran/24945
	* gfortran.dg/open_status_2.f90: Fix wrong PR number in comment.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/open_status_2.f90

Comment 7 Janne Blomqvist 2005-12-04 22:39:43 UTC
No problems have been reported with the patch, closing the bug as fixed.