<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 661: New 27.6.1.2.2 changes make special extractions useless</title>
<meta property="og:title" content="Issue 661: New 27.6.1.2.2 changes make special extractions useless">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue661.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#CD1">CD1</a> status.</em></p>
<h3 id="661"><a href="lwg-defects.html#661">661</a>. New 27.6.1.2.2 changes make special extractions useless</h3>
<p><b>Section:</b> 31.7.5.3.2 <a href="https://wg21.link/istream.formatted.arithmetic">[istream.formatted.arithmetic]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2007-04-01 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#istream.formatted.arithmetic">issues</a> in [istream.formatted.arithmetic].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
To the more drastic changes of 31.7.5.3.2 <a href="https://wg21.link/istream.formatted.arithmetic">[istream.formatted.arithmetic]</a> in the current draft N2134 belong
the explicit description of the extraction of the types short and int in
terms of as-if code fragments.
</p>

<ol>
<li>
The corresponding as-if extractions in paragraph 2 and 3 will never
result in a change of the operator&gt;&gt; argument val, because the
contents of the local variable lval is in no case written into val.
Furtheron both fragments need a currently missing parentheses in the
beginning of the if-statement to be valid C++.
</li>
<li>
I would like to ask whether the omission of a similar explicit
extraction of unsigned short and unsigned int in terms of long -
compared to their corresponding new insertions, as described in 31.7.6.3.2 <a href="https://wg21.link/ostream.inserters.arithmetic">[ostream.inserters.arithmetic]</a>, is a deliberate decision or an
oversight.
</li>
</ol>


<p id="res-661"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>
In 31.7.5.3.2 <a href="https://wg21.link/istream.formatted.arithmetic">[istream.formatted.arithmetic]</a>/2 change the current as-if code fragment
</p>
<blockquote><pre>
typedef num_get&lt;charT,istreambuf_iterator&lt;charT,traits&gt; &gt; numget;
iostate err = 0;
long lval;
use_facet&lt;numget&gt;(loc).get(*this, 0, *this, err, lval );
if (err == 0) <ins>{</ins>
  <del>&amp;&amp;</del> <ins>if</ins> (lval &lt; numeric_limits&lt;short&gt;::min() || numeric_limits&lt;short&gt;::max() &lt; lval)<del>)</del>
      err = ios_base::failbit;
  <ins>else
    val = static_cast&lt;short&gt;(lval);
}</ins>
setstate(err);
</pre></blockquote>

<p>
Similarily in 31.7.5.3.2 <a href="https://wg21.link/istream.formatted.arithmetic">[istream.formatted.arithmetic]</a>/3 change the current as-if fragment
</p>

<blockquote><pre>
typedef num_get&lt;charT,istreambuf_iterator&lt;charT,traits&gt; &gt; numget;
iostate err = 0;
long lval;
use_facet&lt;numget&gt;(loc).get(*this, 0, *this, err, lval );
if (err == 0) <ins>{</ins>
  <del>&amp;&amp;</del> <ins>if</ins> (lval &lt; numeric_limits&lt;int&gt;::min() || numeric_limits&lt;int&gt;::max() &lt; lval)<del>)</del>
      err = ios_base::failbit;
  <ins>else
    val = static_cast&lt;int&gt;(lval);
}</ins>
setstate(err);
</pre></blockquote>
</li>
<li>
---
</li>
</ol>


<p><i>[
Kona (2007): Note to the editor: the name lval in the call to <code>use_facet</code>
is incorrectly italicized in the code fragments corresponding to
<code>operator&gt;&gt;(short &amp;)</code> and <code>operator &gt;&gt;(int &amp;)</code>. Also, val -- which appears
twice on the line with the <code>static_cast</code> in the proposed resolution --
should be italicized. Also, in response to part two of the issue: this
is deliberate.
]</i></p>





</body>
</html>
