[llvm-bugs] [Bug 38052] New: std::fstream still good after closing and updating content

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 4 01:09:50 PDT 2018


            Bug ID: 38052
           Summary: std::fstream still good after closing and updating
           Product: libc++
           Version: unspecified
          Hardware: Macintosh
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: grene at web.de
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

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 << "Hello, World!\n";
    std::cout << "good(): "  << ofs.good()
              << " fail(): " << ofs.fail()
              << " bad(): "  << ofs.bad()
              << " eof(): "  << ofs.eof() << std::endl;
    return 0;

// http://coliru.stacked-crooked.com/a/cfaeb32849c9cfad

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

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180704/f3c3a8f1/attachment.html>

More information about the llvm-bugs mailing list