basic_osyncstream::rdbuf
needs a const_cast
Section: 31.11.3.1 [syncstream.osyncstream.overview] Status: C++20 Submitter: Tim Song Opened: 2018-06-29 Last modified: 2021-02-25
Priority: 0
View all other issues in [syncstream.osyncstream.overview].
View all issues with C++20 status.
Discussion:
The current specification of basic_osyncstream::rdbuf()
is
syncbuf_type* rdbuf() const noexcept { return &sb; }
This is ill-formed because the exposition-only member sb
is const
inside this const
member function,
but the return type is a pointer to non-const
syncbuf_type
. It needs to cast away the constness, consistent
with the other streams with embedded stream buffers (such as string and file streams).
[2018-07-20 Status set to Tentatively Ready after five positive votes on the reflector.]
[2018-11, Adopted in San Diego]
Proposed resolution:
This wording is relative to N4750.
Change 31.11.3.1 [syncstream.osyncstream.overview], class template basic_osyncstream
synopsis, as indicated:
namespace std { template<class charT, class traits, class Allocator> class basic_osyncstream : public basic_ostream<charT, traits> { public: […] // 31.11.3.3 [syncstream.osyncstream.members], member functions void emit(); streambuf_type* get_wrapped() const noexcept; syncbuf_type* rdbuf() const noexcept { return const_cast<syncbuf_type*>(&sb); } […] }; }