[LLVMbugs] [Bug 19518] New: libc++ stringstream extraction doesn't properly throw exceptions

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Apr 22 20:18:26 PDT 2014


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

            Bug ID: 19518
           Summary: libc++ stringstream extraction doesn't properly throw
                    exceptions
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: mclow.lists at gmail.com
          Reporter: benpope81 at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

Extracting a char from an empty stringstream sets badbit, failbit and eofbit,
but an exception is not thrown in many cases.

#include <sstream>
#include <iostream>

void test_iostate(std::ios_base::iostate state)
{
   char c;
   std::stringstream ss;
   try
   {
      ss.exceptions(state);
      ss >> c;
      std::cout << "Didn't throw\n";
   }
   catch(std::ios_base::failure const& ex)
   {
      std::cout << "Threw: " << ex.what() << "\n";
   }
}
int main()
{
   test_iostate(std::ios_base::eofbit);
   test_iostate(std::ios_base::badbit);
   test_iostate(std::ios_base::failbit);
   test_iostate(std::ios_base::eofbit|std::ios_base::badbit);
   test_iostate(std::ios_base::eofbit|std::ios_base::failbit);
   test_iostate(std::ios_base::badbit|std::ios_base::failbit);

test_iostate(std::ios_base::eofbit|std::ios_base::badbit|std::ios_base::failbit);
}


$ clang++ io_fail.cpp -stdlib=libc++ -lc++abi
$ ./a.out
Didn't throw
Didn't throw
Didn't throw
Threw: ios_base::clear: unspecified iostream_category error
Didn't throw
Threw: ios_base::clear: unspecified iostream_category error
Threw: ios_base::clear: unspecified iostream_category error

$ clang++ io_fail.cpp
$ ./a.out
Threw: basic_ios::clear
Didn't throw
Threw: basic_ios::clear
Threw: basic_ios::clear
Threw: basic_ios::clear
Threw: basic_ios::clear
Threw: basic_ios::clear


bug15949#c1 appears to be relevant.

-- 
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/20140423/960cf981/attachment.html>


More information about the llvm-bugs mailing list