public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libstdc++/10674: fstream fails to open files in in/out mode if file doesn't exist
@ 2003-05-08  1:46 daniel.lemire
  0 siblings, 0 replies; 2+ messages in thread
From: daniel.lemire @ 2003-05-08  1:46 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10674
>Category:       libstdc++
>Synopsis:       fstream fails to open files in in/out mode if file doesn't exist
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 08 01:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     daniel.lemire@nrc.gc.ca
>Release:        gcc version 3.4 20030507 (experimental) +  gcc version 3.2.3
>Organization:
>Environment:
linux 2.4.18-3 (RedHat 7.3) on 686
>Description:
If one wants to open a file for random access (in/out)
so that the compiler automatically createst the file
when the file doesn't exist, one would do

fstream s("test.txt",ios::in |ios::out);

This will fail if fstream when the file doesn't exist.
It didn't fail with previous compilers (pre 3.x series).

>How-To-Repeat:
given the file test.cpp below
===================
#include <fstream>
using namespace std;

int main() {
		fstream s("test.txt",ios::in | ios::out);
		if(!s.is_open()) cout << "bug!"<<endl;
		return 0;
}
===============
do

g++ -o a.out test.cpp -O2

followed by

./a.out

make sure test.txt doesn't exist and you'll
get 

bug!


>Fix:
Revert back to gcc 2.96 or else

  FileStream->open( FileName, std::ios::in | std::ios::out);
  if(! FileStream->is_open()) {
		 FileStream->clear();
		 FileStream->open( FileName, std::ios::in | std::ios::out| std::ios::trunc);
	}

since the trunc (truncate) apparently allows you to
create a file if none is present.

The code above is obviously very ugly.
>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: libstdc++/10674: fstream fails to open files in in/out mode if file doesn't exist
@ 2003-05-08 11:27 paolo
  0 siblings, 0 replies; 2+ messages in thread
From: paolo @ 2003-05-08 11:27 UTC (permalink / raw)
  To: daniel.lemire, gcc-bugs, gcc-prs, nobody, paolo

Synopsis: fstream fails to open files in in/out mode if file doesn't exist

Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Thu May  8 11:27:48 2003
Responsible-Changed-Why:
    .
State-Changed-From-To: open->closed
State-Changed-By: paolo
State-Changed-When: Thu May  8 11:27:48 2003
State-Changed-Why:
    Definitely, not a bug. Current libstdc++ strictly conforms
    to the ISO standard, and 27.8.1.3,2 says the in|out is
    equivalent to C library "r+", that is file _must_ exist.
    Thanks for your report.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10674


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

end of thread, other threads:[~2003-05-08 11:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-08  1:46 libstdc++/10674: fstream fails to open files in in/out mode if file doesn't exist daniel.lemire
2003-05-08 11:27 paolo

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).