[LLVMbugs] [Bug 21586] New: libc++ operator>>(istream&, std::string &s) not throwing exception when failbit is set and failbit exceptions enabled

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Nov 16 15:56:23 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21586

            Bug ID: 21586
           Summary: libc++ operator>>(istream&, std::string &s) not
                    throwing exception when failbit is set and failbit
                    exceptions enabled
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: seth.cantrell at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

I have a simple program which I believe should be throwing an exception:

    // http://coliru.stacked-crooked.com/a/464c105f4ec53104

    #include <sstream>
    #include <string>

    int main() {
        std::stringstream ss("");
        ss.exceptions(std::ios::failbit);
        std::string s;
        ss >> s; // not throwing an exception under libc++
    }

With libstdc++ and VC++'s this program does indeed throw an exception. However
with libc++ it does not. Interestingly a direct check of the streams failbit
shows that libc++'s implementation is setting the failbit, as are the other
implementations, but for some reason this does not cause an exception to be
thrown when the streaming operator fails.

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

    #include <sstream>
    #include <string>
    #include <iostream>

    int main() {
        std::stringstream ss("");
        std::string s;
        ss >> s;
        std::cout << ss.fail() << '\n'; // prints '1' for all tested
implementations
    }

If failbit exceptions are enabled after the bit is set, the .exceptions()
member function throws as expected:

    // http://coliru.stacked-crooked.com/a/601cb5d7c5c2b156

    #include <sstream>
    #include <string>

    int main() {
        std::stringstream ss("");
        std::string s;
        ss >> s;
        ss.exceptions(std::ios::failbit); // throws on all tested
implementations
    }

I don't know what version of libc++ is being used on
coliru.stacked-crooked.com, but I'm also reproducing this issue with r222085 /
9a1468f79ea23f14a258af094af06993fe72e3a9

-- 
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/20141116/d6bb45c4/attachment.html>


More information about the llvm-bugs mailing list