This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/7424: libstdc++: ifstream::open() does not work on used ifstream objects


>Number:         7424
>Category:       libstdc++
>Synopsis:       libstdc++: ifstream::open() does not work on used ifstream objects
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 28 06:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Roger Leigh
>Release:        3.1.1 20020703 (Debian prerelease) (Debian testing/unstable)
>Organization:
N/A
>Environment:
System: Linux whinlatter 2.4.18 #6 Thu Jul 11 11:41:55 BST 2002 i686 unknown
Architecture: i686

	
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds2/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/g++-v3-3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-__cxa_atexit --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
The following code works with g++-2.95, but not g++-3.0 or g++-3.1
(example).  For the latter two, re-using the same ifstream object
(ifstream::open()) results in failure.  Defining and using a new
ifstream object is OK.

Test output (g++-3.1):
roger@whinlatter:~/cc/16$ ./test2 
Open(1) succeeded
Current file contents:
[file contents]

***EOF***
Unable to open filename for appending.

Test output (6++-2.95):
roger@whinlatter:~/cc/16$ ./test2 
Open(1) succeeded
Current file contents:
[file contents]

***EOF***
Open(2) succeeded

Note the second open fails for g++ 3.1.

I'm willing to provide any additional data you might require.  My
system is Debian GNU/Linux (sid).  As my incoming email is broken
right now (at the ISP), I might not be reachable.  My phone number
is +44 01254 664642 (UK).
>How-To-Repeat:
If lines 16-23 are commented out, it will run successfully (gcc 3.0
and 3.1) otherwise both will fail to reopen the file (but gcc 2.95.2
will succeed).

#include <fstream>
#include <iostream>
using std::cout;
using std::ifstream;

int main()
{
  char* filename = "filename";
  ifstream infile(filename);
  if (!infile)
    {
      cout << "Unable to open " << filename << " for reading.\n";
      return 1;
    }
  cout << "Open(1) succeeded\n";
  if (infile)
    {
      cout << "Current file contents:\n";
      char ch;
      while (infile.get(ch))
	cout << ch;
      cout << "\n***EOF***\n";
    }
  infile.close();

  infile.open(filename);
  if (!infile)
    {
      cout << "Unable to open " << filename << " for appending.\n";
      return 1;
    }
  cout << "Open(2) succeeded\n";
  // read file again
  infile.close();

  return 0;
}
>Fix:
         None, sorry.  I'm only just learning C++, and found this error when I was
	 learning about iostream and file I/O.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]