This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

3127. basic_osyncstream::rdbuf needs a const_cast

Section: 28.10.3.1 [syncstream.osyncstream.overview] Status: WP Submitter: Tim Song Opened: 2018-06-29 Last modified: 2018-11-13

Priority: 0

View all issues with WP 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.

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