3127. basic_osyncstream::rdbuf needs a const_cast

Section: [syncstream.osyncstream.overview] Status: C++20 Submitter: Tim Song Opened: 2018-06-29 Last modified: 2021-02-25 10:48:01 UTC

Priority: 0

View all other issues in [syncstream.osyncstream.overview].

View all issues with C++20 status.


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.

  1. Change [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> {
        // [syncstream.osyncstream.members], member functions
        void emit();
        streambuf_type* get_wrapped() const noexcept;
        syncbuf_type* rdbuf() const noexcept { return const_cast<syncbuf_type*>(&sb); }