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

2243. istream::putback problem

Section: 31.7.5.4 [istream.unformatted] Status: C++20 Submitter: Juan Soulie Opened: 2013-03-01 Last modified: 2021-02-25

Priority: 3

View all other issues in [istream.unformatted].

View all issues with C++20 status.

Discussion:

In 31.7.5.4 [istream.unformatted] / 34, when describing putback, it says that "rdbuf->sputbackc()" is called. The problem are not the obvious typos in the expression, but the fact that it may lead to different interpretations, since nowhere is specified what the required argument to sputbackc is.

It can be guessed to be "rdbuf()->sputbackc(c)", but "rdbuf()->sputbackc(char_type())" or just anything would be as conforming (or non-conforming) as the first guess.

[2017-12-12, Jonathan comments and provides wording]

Fix the bogus expression, and change sputbackc() to just sputbackc since we're talking about the function, not an expression sputbackc() (which isn't a valid expression any more than rdbuf->sputbackc() is). Make the corresponding change to the equivalent wording in p36 too.

[ 2017-12-14 Moved to Tentatively Ready after 6 positive votes on c++std-lib. ]

[2018-3-17 Adopted in Jacksonville]

Proposed resolution:

This wording is relative to N4713.

  1. Change 31.7.5.4 [istream.unformatted] as shown:

    basic_istream<charT, traits>& putback(char_type c);
    

    -34- Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit. After constructing a sentry object, if !good() calls setstate(failbit) which may throw an exception, and return. If rdbuf() is not null, calls rdbuf()->sputbackc(c). If rdbuf() is null, or if sputbackc() returns traits::eof(), calls setstate(badbit) (which may throw ios_base::failure (31.5.4.4 [iostate.flags])). [Note: This function extracts no characters, so the value returned by the next call to gcount() is 0. — end note]

    -35- Returns: *this.

    basic_istream<charT, traits>& unget();
    

    -36- Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit. After constructing a sentry object, if !good() calls setstate(failbit) which may throw an exception, and return. If rdbuf() is not null, calls rdbuf()->sungetc(). If rdbuf() is null, or if sungetc() returns traits::eof(), calls setstate(badbit) (which may throw ios_base::failure (31.5.4.4 [iostate.flags])). [Note: This function extracts no characters, so the value returned by the next call to gcount() is 0. — end note]

    -37- Returns: *this.