<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - std::fstream still good after closing and updating content"
   href="https://bugs.llvm.org/show_bug.cgi?id=38052">38052</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::fstream still good after closing and updating content
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>grene@web.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have a simple program that should show the problem. - with libc++ the stream
is still good after closing and further operation. Since also the file content
was not updated - at least the stream operation fails on the closed stream and
should set either failbit or badbit to reflect the situation.

#include <iostream>
#include <fstream>

int main(int argc, const char * argv[])
{
    std::fstream ofs("test.txt", std::ios::out | std::ios::trunc);
    ofs << "Hello, World!\n";
    ofs.close();
    ofs << "Hello, World!\n";
    std::cout << "good(): "  << ofs.good()
              << " fail(): " << ofs.fail()
              << " bad(): "  << ofs.bad()
              << " eof(): "  << ofs.eof() << std::endl;
    return 0;
}

// <a href="http://coliru.stacked-crooked.com/a/cfaeb32849c9cfad">http://coliru.stacked-crooked.com/a/cfaeb32849c9cfad</a>

With libc++ I get
good(): 1 fail(): 0 bad(): 0 eof(): 0

Expected (or with libstdc++):
good(): 0 fail(): 1 bad(): 1 eof(): 0

I have tested on OSX with Xcode 9.4.1
Apple LLVM version 9.1.0 (clang-902.0.39.2)

or on Linux:
clang version 3.8.0</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>