<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2243: istream::putback problem</title>
<meta property="og:title" content="Issue 2243: istream::putback problem">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2243.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++20">C++20</a> status.</em></p>
<h3 id="2243"><a href="lwg-defects.html#2243">2243</a>. <code>istream::putback</code> problem</h3>
<p><b>Section:</b> 31.7.5.4 <a href="https://wg21.link/istream.unformatted">[istream.unformatted]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Juan Soulie <b>Opened:</b> 2013-03-01 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#istream.unformatted">issues</a> in [istream.unformatted].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In 31.7.5.4 <a href="https://wg21.link/istream.unformatted">[istream.unformatted]</a> / 34, when describing <code>putback</code>, it says that "<code>rdbuf-&gt;sputbackc()</code>" 
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 <code>sputbackc</code> is.
<p/>
It can be guessed to be "<code>rdbuf()-&gt;sputbackc(c)</code>", but "<code>rdbuf()-&gt;sputbackc(char_type())</code>" or 
just anything would be as conforming (or non-conforming) as the first guess.
</p>

<p><i>[2017-12-12, Jonathan comments and provides wording]</i></p>

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

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

<p><i>[2018-3-17 Adopted in Jacksonville]</i></p>



<p id="res-2243"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4713">N4713</a>.</p>

<ol>
<li><p>Change 31.7.5.4 <a href="https://wg21.link/istream.unformatted">[istream.unformatted]</a> as shown:</p>

<blockquote>
<pre>
basic_istream&lt;charT, traits&gt;&amp; putback(char_type c);
</pre>
<blockquote>
<p>
-34- <i>Effects:</i> Behaves as an unformatted input function (as described above), except that the function
first clears <code>eofbit</code>. After constructing a sentry object, if <code>!good()</code> calls 
<code>setstate(failbit)</code> which may throw an exception, and return. If <code>rdbuf()</code> is not null, calls 
<code>rdbuf<ins>()</ins>-&gt;sputbackc(<ins>c</ins>)</code>. If <code>rdbuf()</code> is null, or if 
<code>sputbackc<del>()</del></code> returns <code>traits::eof()</code>, calls <code>setstate(badbit)</code> (which may throw 
<code>ios_base::failure</code> (31.5.4.4 <a href="https://wg21.link/iostate.flags">[iostate.flags]</a>)). 
[<i>Note:</i> This function extracts no characters, so the value returned by the next call to <code>gcount()</code> 
is <code>0</code>. &mdash; <i>end note</i>]
<p/>
-35- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
basic_istream&lt;charT, traits&gt;&amp; unget();
</pre>
<blockquote>
<p>
-36- <i>Effects:</i> Behaves as an unformatted input function (as described above), except that the function
first clears <code>eofbit</code>. After constructing a sentry object, if <code>!good()</code> calls 
<code>setstate(failbit)</code> which may throw an exception, and return. If <code>rdbuf()</code> is not null, calls 
<code>rdbuf()-&gt;sungetc()</code>. If <code>rdbuf()</code> is null, or if <code>sungetc<del>()</del></code> returns 
<code>traits::eof()</code>, calls <code>setstate(badbit)</code> (which may throw <code>ios_base::failure</code> 
(31.5.4.4 <a href="https://wg21.link/iostate.flags">[iostate.flags]</a>)). 
[<i>Note:</i> This function extracts no characters, so the value returned by the next call to <code>gcount()</code> is 
<code>0</code>. &mdash; <i>end note</i>]
<p/>
-37- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
