<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2286: stringbuf::underflow() underspecified</title>
<meta property="og:title" content="Issue 2286: stringbuf::underflow() underspecified">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2286.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#Open">Open</a> status.</em></p>
<h3 id="2286"><a href="lwg-active.html#2286">2286</a>. <code>stringbuf::underflow()</code> underspecified</h3>
<p><b>Section:</b> 31.8.2.5 <a href="https://wg21.link/stringbuf.virtuals">[stringbuf.virtuals]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Sergey Zubkov <b>Opened:</b> 2013-08-29 <b>Last modified:</b> 2018-06-12</p>
<p><b>Priority: </b>4
</p>
<p><b>View other</b> <a href="lwg-index-open.html#stringbuf.virtuals">active issues</a> in [stringbuf.virtuals].</p>
<p><b>View all other</b> <a href="lwg-index.html#stringbuf.virtuals">issues</a> in [stringbuf.virtuals].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In 31.8.2.5 <a href="https://wg21.link/stringbuf.virtuals">[stringbuf.virtuals]</a>/1, <code>basic_stringbuf::underflow()</code> is specified to unconditionally 
return <code>traits::eof()</code> when a read position is not available.
<p/>
The semantics of <code>basic_stringbuf</code> require, and existing libraries implement it so that this function makes 
a read position available if possible to do so, e.g. if some characters were inserted into the stream since the 
last call to <code>overflow()</code>, resulting in <code>pptr() &gt; egptr()</code>. Compare to the conceptually similar 
99 [depr.strstreambuf.virtuals]/15.
</p>

<p><i>[2018-06-06, Billy argues for NAD]</i></p>

<p>
The existing "Any character in the underlying buffer which has been initialized is considered to be part of the input sequence." 
sentence already describes what the <code>stringbuf</code> is supposed to do to the get area. The specific mechanism that the 
<code>stringbuf</code> uses to alter the get area is unspecified because the mechanism by which the <code>stringbuf</code> 
remembers the "high water mark" is unspecified.
<p/>
Consider the following:
</p>
<blockquote><pre>
stringstream s;
s &lt;&lt; "Hello";
s.seekp(0);
string x;
s &gt;&gt; x;
</pre></blockquote>
<p>
Before this P/R, this will store <code>Hello</code> in <code>x</code>, because the characters <code>Hello</code> are initialized. 
After this P/R, the "written put area" is empty, so it will store the empty string in <code>x</code>.
<p/>
Saying that the initialized part of the string is used already describes what needs to happen here.
</p>

<p><i>[2018-06 Rapperswil Wednesday issues processing]</i></p>

<p>Billy to provide rationale for closing as NAD.</p>



<p id="res-2286"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3691.</p>

<ol>

<li><p>Change 31.8.2.5 <a href="https://wg21.link/stringbuf.virtuals">[stringbuf.virtuals]</a> as indicated:</p>

<blockquote>
<pre>
int_type underflow();
</pre><blockquote>
<p>
-1- <i>Returns:</i> If the input sequence has a read position available <ins>or the function makes a read position available 
(as described below)</ins>, returns <code>traits::to_int_type(*gptr())</code>. Otherwise, returns <code>traits::eof()</code>. Any 
character in the underlying buffer which has been initialized is considered to be part of the input sequence.
<p/>
<ins>-?- The function can make a read position available only if <code>(mode &amp; ios_base::in) != 0</code> and if the write 
next pointer <code>pptr()</code> is not null and is greater than the current read end pointer <code>egptr()</code>. To make a read 
position available, the function alters the read end pointer <code>egptr()</code> to equal <code>pptr()</code>.</ins>
</p>
</blockquote></blockquote>
</li>

</ol>





</body>
</html>
