https://bugs.llvm.org/show_bug.cgi?id=42572

            Bug ID: 42572
           Summary: std::ofstream silently fails to write files when they
                    can't be created
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: y...@tsoft.com
                CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com

The example from cplusplus.com
http://www.cplusplus.com/reference/fstream/ofstream/open/ with the modified
file name fails silently, showing how error-prone the file interface is:


> #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;
> }

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:
> 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


FreeBSD 12 amd64, clang8.


Yuri

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to