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

2576. istream_iterator and ostream_iterator should use std::addressof

Section: 24.6 [stream.iterators] Status: C++17 Submitter: Tim Song Opened: 2016-01-01 Last modified: 2017-07-30

Priority: 0

View all other issues in [stream.iterators].

View all issues with C++17 status.

Discussion:

To defend against overloaded unary &. This includes the constructors of both iterators, and istream_iterator::operator->.

Note that {i,o}stream_type are specializations of basic_{i,o}stream, but the constructors might still pick up an overloaded & via the traits template parameter. This change also provides consistency with std::experimental::ostream_joiner (which uses std::addressof).

[2016-02, Issues Telecon]

P0; move to Tentatively Ready.

Proposed resolution:

This wording is relative to N4567.

  1. Edit 24.6.2.2 [istream.iterator.cons]/3+4 as indicated:

    istream_iterator(istream_type& s);
    

    -3- Effects: Initializes in_stream with &saddressof(s). value may be initialized during construction or the first time it is referenced.

    -4- Postcondition: in_stream == &saddressof(s).

  2. Edit 24.6.2.3 [istream.iterator.ops]/2 as indicated:

    const T* operator->() const;
    

    -2- Returns: &addressof(operator*()).

  3. Edit 24.6.3.2 [ostream.iterator.cons.des]/1+2 as indicated:

    ostream_iterator(ostream_type& s);
    

    -1- Effects: Initializes out_stream with &saddressof(s) and delim with null.

    ostream_iterator(ostream_type& s, const charT* delimiter);
    

    -2- Effects: Initializes out_stream with &saddressof(s) and delim with delimiter.