<html>
    <head>
      <base href="https://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 --- - basic_ostream::write() does not call basic_streambuf::sputn() if n is zero"
   href="https://llvm.org/bugs/show_bug.cgi?id=24437">24437</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>basic_ostream::write() does not call basic_streambuf::sputn() if n is zero
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.4
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sadyrovr@ncbi.nlm.nih.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello,

We have a cross-platform library that is compiled by GCC, ICC, MS VS and Clang
compilers on a few platforms.
There is a template code in the library which uses basic_iostream with a class
derived from basic_streambuf.
That class (based on basic_streambuf) creates a file on first write (there
might be none writes and only reads).
In some instantiations of that template code basic_iostream::write() is called
only once, with n = 0.

In this case, Clang/libc++ compiled code does not call basic_streambuf::sputn()
(which in turn calls xsputn() of our class).
Consequently, that file we expect to exist is not created.

We have no such issue with this code compiled by any other compiler we use.
(Our implementation of xsputn() is called in this case and files are created).

We took a look at the source code of libc++
(<a href="http://llvm.org/svn/llvm-project/libcxx/trunk/include/ostream">http://llvm.org/svn/llvm-project/libcxx/trunk/include/ostream</a>) for this
particular issue and found the cause:

basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
...
        if (__sen && __n)
        {
            if (this->rdbuf()->sputn(__s, __n) != __n)
...

We checked the source code of libstdc++ as well, it does not check for n being
non-zero.
It seems all other implementations of standard library we use do not do this as
well (otherwise, we would have experienced the same issue).

Could someone take a look at this?

Thanks,
Rafael.</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>