<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63674>63674</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc++] adding std::stringbuf::setbuf to manipulate get/put pointers
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alexswerner
      </td>
    </tr>
</table>

<pre>
    Version: llvmorg-16.0.6

While porting a project from libstdc++ to libc++ I encountered that std::stringbuf::setbuf is not doing anything in libc++. While this is within the requirements of the standard, it would be useful to implement changing the buffer pointers in when using user-supplied buffers. 

Right now basic_streambuf::setbuf is not overloaded in basic_stringbuf. I'm suggesting adding it like so:
```
diff --git a/libcxx/include/sstream b/libcxx/include/sstream
index 31c242365..17966fa82 100644
--- a/libcxx/include/sstream
+++ b/libcxx/include/sstream
@@ -379,6 +379,7 @@ protected:
     int_type underflow() override;
     int_type pbackfail(int_type __c = traits_type::eof()) override;
     int_type overflow (int_type __c = traits_type::eof()) override;
+ basic_stringbuf* setbuf(char_type* __s, streamsize __n) override;
 pos_type seekoff(off_type __off, ios_base::seekdir __way,
 ios_base::openmode __wch = ios_base::in | ios_base::out) override;
 _LIBCPP_HIDE_FROM_ABI_VIRTUAL
@@ -702,6 +703,19 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c)
 return traits_type::not_eof(__c);
 }
 
+template <class _CharT, class _Traits, class _Allocator>
+basic_stringbuf<_CharT, _Traits, _Allocator>*
+basic_stringbuf<_CharT, _Traits, _Allocator>::setbuf(char_type* __s,
+ streamsize __n)
+{
+    if (__s && __n >= 0)
+ {
+        setg(__s, __s, __s + __n);
+        setp(__s, __s + __n);
+    }
+    return this;
+}
+
 template <class _CharT, class _Traits, class _Allocator>
 typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
 basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off,
```
This would align the functionality with libstc++.

References:
* libstc++ std::stringbuf::setbuf implementation [here](https://github.com/gcc-mirror/gcc/blob/85d8e0d8d5342ec8b4e6a54e22741c30b33c6f04/libstdc%2B%2B-v3/include/std/sstream#L378) using _M_sync from [here](https://github.com/gcc-mirror/gcc/blob/85d8e0d8d5342ec8b4e6a54e22741c30b33c6f04/libstdc%2B%2B-v3/include/bits/sstream.tcc#L246)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVlmP2zYQ_jX0y8CGTOqwH_zgI0YX2KBBsE0fBYocSezKpEpS693--oI6vHayOdDkoYYh8Zjj48wnznDnVKURNyTZkeQw452vjd3wBp_dGa1GOyuMfNl8QuuU0YRtoWmeTsZW82W6iBYpiQ4k2g7PP2vVILTGeqUr4NBa8xcKD6U1J2hU4bwUhO4I3YE3YWGa3QFqYTrt0aIEX3MPzkvCtoRtnbdKV0VXjlP0RVeCcqCNB2l6T_rF12Gg9JXVBQx4fK1ckD-rIAS-RrD4d6csnlB7B6bs15znWnIrCd2D8nA2XSOhQOgcll0TAKtT2_Q6IGquq-AwKBZdWaKF1qiA3wUQ5xo1dC5IdA7t3HVt2yiUo6xbwHXYPqqq9qDNGQrulMidt8hPXzmxeULbGC5RBkcXhSFEC7gjNDuB66oK3ZAFKfvIeGjUI4IzwejgPI3Gfz-VqixhPq-UB07oMcTx-ZnQo9Ki6SQSenQDMCi-uT1YU1riM7CloDFlabJYLLN1mpZ8RWEZRWkcD2Lz-fw73kasfUYDVX7EOYkjEkcwZ9ma0H0KhO6GYQbjVmuNR-FRXqIB4ae0z_1Li9BpibZszJnQFaHrPupWSSRs95Z4W3DxWHLVELq6LOa5AMIO4C1X3vVrQ0LRlIPZH7ActgMO-AWW-_DdEobQLQz8InQlam4HY3QLee7ClzCE1al_glf9NuDWDBjAIT6aMpgyZTlB7Rf2oIzLC-5w4jQ-SmUhz8_8hdD9aOlWyLSoT0YGI2dR9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