<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 --- - std::getline does not read data after calling ifstream::clear() (Mavericks)"
   href="http://llvm.org/bugs/show_bug.cgi?id=17688">17688</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::getline does not read data after calling ifstream::clear() (Mavericks)
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>hhinnant@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>bernhard@icsi.berkeley.edu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=11423" name="attach_11423" title="readline behavior demonstration">attachment 11423</a> <a href="attachment.cgi?id=11423&action=edit" title="readline behavior demonstration">[details]</a></span>
readline behavior demonstration

The following program demonstrates an inconsistency in std::getline behavior
between libc++ and libstdc++ (using clang3.3).

The program opens the file testfile, reads it until eof, then clears the error
bits using ifstream::clear and tries to read from the same filehandle again to
see if new data was appended to the file.

Using libstdc++ (no matter which compiler), if you append data to testfile
while the program is running, the data will be read by the getline call in the
next loop iteration.

In clang 3.3 on OS-X with libc++, after the first time the file end is
encountered, getline will always fail and set the eof bit on all following
calls, without reading any data that has been appended to the file.
Uncommenting the workaround, which just seeks to the current position restores
libstdc++ behavior. Compiling against libstdc++ with clang++ -stdlib=libstdc++
also reverts to the old behavior.

Is expected behavior? Am I trying to do this in a way that is not supported or
is this some problem of current libc++ versions?

The clang version that triggers this behavior for me is the most recent one
shipped with XCode for Mavericks:

Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

The libc++ library that is linked against has this version information:
/usr/lib/libc++.1.dylib:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
/usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 48.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
1197.1.1)</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>