<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::ofstream silently fails to write files when they can't be created"
   href="https://bugs.llvm.org/show_bug.cgi?id=42572">42572</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::ofstream silently fails to write files when they can't be created
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>yuri@tsoft.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The example from cplusplus.com
<a href="http://www.cplusplus.com/reference/fstream/ofstream/open/">http://www.cplusplus.com/reference/fstream/ofstream/open/</a> with the modified
file name fails silently, showing how error-prone the file interface is:


<span class="quote">> #include <fstream>

> int main () {
>   std::ofstream ofs;
>   ofs.open ("nonexistent-noexistent/test.txt", std::ofstream::out | std::ofstream::app);

>   ofs << " more lorem ipsum";

>   ofs.close();

>   return 0;
> }</span >

No exception is thrown, no error message is printed.

The kernel trace shows that the error "No such file or directory" is lost by
STL:
<span class="quote">> 47377 ofstream CALL  open(0x20229d,0x209<O_WRONLY|O_APPEND|O_CREAT>,0666<S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH>)
> 47377 ofstream NAMI  "nonexistent-noexistent/test.txt"
> 47377 ofstream RET   open -1 errno 2 No such file or directory</span >


FreeBSD 12 amd64, clang8.


Yuri</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>