Bug 127968

Summary: fstream fails to open a file for reading and writing or create a new file
Product: [Fedora] Fedora Reporter: Guo Yang <yangguo1991>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: bkoz
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-08-05 18:38:02 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Guo Yang 2004-07-15 20:14:42 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040625

Description of problem:
This simple program compiled by g++ failed to run no matter
/tmp/test.txt exits or not. I always get 'Error opening file'

#include <iostream>
#include <fstream>

using namespace std;

int main () {

  std::ios::sync_with_stdio(false);

  fstream filestr("/tmp/test.txt", ios::in|ios::out|ios::app);

  if (filestr.is_open())
  {
    cout << "File successfully open" << endl;
    filestr << "Help wanted!" << endl;
    filestr.close();
  }
  else
  {
    cerr << "Error opening file" << endl;
  }

  return 0;
}

I tried to use g++33 and g++35. Didn't work either.

But this same program compiled by Intel C++ compile 8.0 works. It also
works in Windows when compiled by Visual.NET compiler.

I also tried the same program on Redhat Linux 9.0, didn't work either.

Version-Release number of selected component (if applicable):
gcc-c++-3.4.1-4

How reproducible:
Always

Steps to Reproduce:
1. Open an editor and type in the program and save it to test.cpp
2. g++ test.cpp
3. ./a.out
    

Actual Results:  I always get 'Error opening file' message. And the
file is either intact or not created. 

Expected Results:  Although I should get 'File successfully open', and
a file should be created if it doesn't exist and a sentence 'Help
Wanted' should be appended to the end of file.

Additional info:

Comment 1 Jakub Jelinek 2004-07-15 20:39:30 UTC
I don't have my ISO C++ copy handy now, will look tomorrow.
But from what I have googled around, this test is supposed to fail:
http://www-cdf.fnal.gov/offline/zoom/defects/c++-cd2/lib-iostreams.html
Table 11--File open modes
doesn't list there in|out|app combination and
"If mode is not some combination of flags shown in the table then the
open fails."

Comment 2 Guo Yang 2004-07-15 21:28:27 UTC
Oh, that's right. The book I am using to learn C++ doesn't state that
clearly. I thought any combination would work. Sorry. So the Intel C++
compiler doesn't stick to the standard strictly? Thank you very much.