<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - libc++ operator>>(istream&, std::string &s) not throwing exception when failbit is set and failbit exceptions enabled"
   href="http://llvm.org/bugs/show_bug.cgi?id=21586">21586</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>libc++ operator>>(istream&, std::string &s) not throwing exception when failbit is set and failbit exceptions enabled
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>seth.cantrell@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have a simple program which I believe should be throwing an exception:

    // <a href="http://coliru.stacked-crooked.com/a/464c105f4ec53104">http://coliru.stacked-crooked.com/a/464c105f4ec53104</a>

    #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.

    // <a href="http://coliru.stacked-crooked.com/a/e4a649ee145b0475">http://coliru.stacked-crooked.com/a/e4a649ee145b0475</a>

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

    // <a href="http://coliru.stacked-crooked.com/a/601cb5d7c5c2b156">http://coliru.stacked-crooked.com/a/601cb5d7c5c2b156</a>

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