<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2544: istreambuf_iterator(basic_streambuf&lt;charT, traits&gt;* s) effects unclear when s is 0</title>
<meta property="og:title" content="Issue 2544: istreambuf_iterator(basic_streambuf&lt;charT, traits&gt;* s) effects unclear when s is 0">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2544.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++17">C++17</a> status.</em></p>
<h3 id="2544"><a href="lwg-defects.html#2544">2544</a>. <code>istreambuf_iterator(basic_streambuf&lt;charT, traits&gt;* s)</code> effects unclear when <code>s</code> is <code>0</code></h3>
<p><b>Section:</b> 24.6.4.3 <a href="https://wg21.link/istreambuf.iterator.cons">[istreambuf.iterator.cons]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> S. B. Tam <b>Opened:</b> 2015-10-05 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
N4527 24.6.4.3 <a href="https://wg21.link/istreambuf.iterator.cons">[istreambuf.iterator.cons]</a> does not mention what the effect of calling 
<code>istreambuf_iterator(basic_streambuf&lt;charT, traits&gt;* s)</code> is when <code>s</code> is a null pointer. 
It should be made clear that this case is well-formed and the result is a end-of-stream iterator.
<p/>
Daniel:
<p/>
According to 24.6.4 <a href="https://wg21.link/istreambuf.iterator">[istreambuf.iterator]</a> p1:
</p>
<blockquote><p>
[&hellip;] The default constructor <code>istreambuf_iterator()</code> and the constructor <code>istreambuf_iterator(0)</code> both 
construct an end-of-stream iterator object suitable for use as an end-of-range. [&hellip;]
</p></blockquote>
<p>
This indicates that the described constructor creates an end-of-stream iterator, but this wording is part of the introductory 
wording and I recommend to make 24.6.4.3 <a href="https://wg21.link/istreambuf.iterator.cons">[istreambuf.iterator.cons]</a> clearer, because the existing specification is already
flawed, e.g. it never specifies when and how the exposition-only-member <code>sbuf_</code> is initialized. The proposed wording 
below attempts to solve these problems as well.
</p>

<p>
<strong>Previous resolution [SUPERSEDED]:</strong>
</p>
<blockquote class="note">
<p>This wording is relative to N4527.</p>

<ol>
<li>
<p>Change 24.6.4.3 <a href="https://wg21.link/istreambuf.iterator.cons">[istreambuf.iterator.cons]</a> as indicated:
<p/>
[<i>Editorial note</i>: The proposed wording changes also performs some editorial clean-up of the existing mismatches
of the declarations in the class template synopsis and the individual member specifications. The below wording intentionally
does not say anything about the concrete value of <code>sbuf_</code> for end-of-stream iterator values, because that
was never specified before; in theory, this could be some magic non-null pointer that can be used in constant expressions. 
But the wording could be drastically simplified by requiring <code>sbuf_</code> to be a null pointer for an end-of-stream iterator value, 
since I have not yet seen any implementation where this requirement does not hold. &mdash; <i>end editorial note</i>]
</p>
<blockquote>
<pre>
constexpr istreambuf_iterator() noexcept;
</pre>
<blockquote>
<p>
-1- <i>Effects</i>: Constructs the end-of-stream iterator.
</p>
</blockquote>
<pre>
istreambuf_iterator(<del>basic_istream&lt;charT,traits&gt;</del><ins>istream_type</ins>&amp; s) noexcept;
<del>istreambuf_iterator(basic_streambuf&lt;charT,traits&gt;* s) noexcept;</del>
</pre>
<blockquote>
<p>
-2- <i>Effects</i>: <ins>If <code>s.rdbuf()</code> is a null pointer, constructs an end-of-stream iterator; otherwise 
initializes  <code>sbuf_</code> with <code>s.rdbuf()</code> and constructs an <code>istreambuf_iterator</code> that uses the 
<code>streambuf_type</code> object <code>*sbuf_</code></ins><del>Constructs an <code>istreambuf_iterator&lt;&gt;</code> that 
uses the <code>basic_streambuf&lt;&gt;</code> object <code>*(s.rdbuf())</code>, or <code>*s</code>, respectively. Constructs 
an end-of-stream iterator if <code>s.rdbuf()</code> is null</del>.
</p>
</blockquote>
<pre>
<ins>istreambuf_iterator(streambuf_type* s) noexcept;</ins>
</pre>
<blockquote>
<p>
<ins>-?- <i>Effects</i>: If <code>s</code> is a null pointer, constructs an end-of-stream iterator; otherwise initializes 
<code>sbuf_</code> with <code>s</code> and constructs an <code>istreambuf_iterator</code> that uses the <code>streambuf_type</code> 
object <code>*sbuf_</code>.</ins>
</p>
</blockquote>
<pre>
istreambuf_iterator(const proxy&amp; p) noexcept;
</pre>
<blockquote>
<p>
-3- <i>Effects</i>: <ins>Initializes <code>sbuf_</code> with <code>p.sbuf_</code> and constructs an <code>istreambuf_iterator</code> 
that uses the <code>streambuf_type</code> object <code>*sbuf_</code></ins><del>Constructs a <code>istreambuf_iterator&lt;&gt;</code> 
that uses the <code>basic_streambuf&lt;&gt;</code> object pointed to by the <code>proxy</code> object's constructor argument 
<code>p</code></del>.
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2015-10-20, Daniel provides alternative wording]</i></p>


<p><i>[2016-08-03 Chicago]</i></p>

<p>Fri AM: Moved to Tentatively Ready</p>


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

<ol>
<li>
<p>Change 24.6.4.3 <a href="https://wg21.link/istreambuf.iterator.cons">[istreambuf.iterator.cons]</a> as indicated:</p>
<blockquote class="note">
<p>
[<i>Drafting note</i>: The proposed wording changes also performs some editorial clean-up of the existing mismatches
of the declarations in the class template synopsis and the individual member specifications. The below wording is 
simplified by requiring <code>sbuf_</code> to be a null pointer for an end-of-stream iterator value, 
since I have not yet seen any implementation where this requirement does not hold. Even if there <em>were</em> such an 
implementation, this would still be conforming, because concrete exposition-only member values are not part of public 
API. &mdash; <i>end drafting note</i>]
</p>
</blockquote>
<blockquote>
<p>
<ins>For each <code>istreambuf_iterator</code> constructor in this section, an end-of-stream iterator is 
constructed if and only if the exposition-only member <code>sbuf_</code> is initialized with a null 
pointer value.</ins>
</p>
<pre>
constexpr istreambuf_iterator() noexcept;
</pre>
<blockquote>
<p>
-1- <i>Effects</i>: <ins>Initializes <code>sbuf_</code> with <code>nullptr</code></ins><del>Constructs the end-of-stream iterator</del>.
</p>
</blockquote>
<pre>
istreambuf_iterator(<del>basic_istream&lt;charT,traits&gt;</del><ins>istream_type</ins>&amp; s) noexcept;
<del>istreambuf_iterator(basic_streambuf&lt;charT,traits&gt;* s) noexcept;</del>
</pre>
<blockquote>
<p>
-2- <i>Effects</i>: <ins>Initializes <code>sbuf_</code> with <code>s.rdbuf()</code></ins><del>Constructs 
an <code>istreambuf_iterator&lt;&gt;</code> that uses the <code>basic_streambuf&lt;&gt;</code> object 
<code>*(s.rdbuf())</code>, or <code>*s</code>, respectively. Constructs 
an end-of-stream iterator if <code>s.rdbuf()</code> is null</del>.
</p>
</blockquote>
<pre>
<ins>istreambuf_iterator(streambuf_type* s) noexcept;</ins>
</pre>
<blockquote>
<p>
<ins>-?- <i>Effects</i>: Initializes <code>sbuf_</code> with <code>s</code>.</ins>
</p>
</blockquote>
<pre>
istreambuf_iterator(const proxy&amp; p) noexcept;
</pre>
<blockquote>
<p>
-3- <i>Effects</i>: <ins>Initializes <code>sbuf_</code> with <code>p.sbuf_</code></ins><del>Constructs a <code>istreambuf_iterator&lt;&gt;</code> 
that uses the <code>basic_streambuf&lt;&gt;</code> object pointed to by the <code>proxy</code> object's constructor argument 
<code>p</code></del>.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
