<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3300: Non-array ssize overload is underconstrained</title>
<meta property="og:title" content="Issue 3300: Non-array ssize overload is underconstrained">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3300.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="3300"><a href="lwg-defects.html#3300">3300</a>. Non-array <code>ssize</code> overload is underconstrained</h3>
<p><b>Section:</b> 24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2019-09-27 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#iterator.range">active issues</a> in [iterator.range].</p>
<p><b>View all other</b> <a href="lwg-index.html#iterator.range">issues</a> in [iterator.range].</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>
The overload of <code>ssize</code> specified in 24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a>/18 has no constraints, 
yet it specializes <code>make_signed_t</code> which has a precondition that its type parameter is an 
integral type or enumeration but not <code>bool</code> (21.3.9.4 <a href="https://wg21.link/meta.trans.sign">[meta.trans.sign]</a>). This 
precondition needs to be propagated to <code>ssize</code> as "<i>Mandates</i> [or <i>Constraints</i>]: 
<code>decltype(c.size())</code> [meets the requirements for the type argument to <code>make_signed</code>]". 
"<i>Mandates</i>" seems to be more in line with LWG guidance since there are no traits nor concepts 
that observe <code>ssize</code>.
</p>

<p><i>[2019-11-16 Issue Prioritization]</i></p>

<p>Priority to 3 after reflector discussion.</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4830">N4830</a>.</p>

<ol>
<li><p>Modify 24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class C&gt; constexpr auto ssize(const C&amp; c)
  -&gt; common_type_t&lt;ptrdiff_t, make_signed_t&lt;decltype(c.size())&gt;&gt;;
</pre>
<blockquote>
<p>
<ins>-?- <i>Mandates:</i> <code>decltype(c.size())</code> is a (possibly <i>cv</i>-qualified) integral or 
enumeration type but not a <code>bool</code> type.</ins>
<p/>
-18- <i>Returns:</i>
<blockquote>
<pre>
static_cast&lt;common_type_t&lt;ptrdiff_t, make_signed_t&lt;decltype(c.size())&gt;&gt;&gt;(c.size())
</pre>
</blockquote>
</p>
</blockquote>
</blockquote>
</li>

</ol></blockquote>

<p><i>[2019-10-28; Tim provides improved wording]</i></p>


<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4835">N4835</a>.</p>

<ol>
<li><p>Modify 24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class C&gt; constexpr auto ssize(const C&amp; c)
  -&gt; common_type_t&lt;ptrdiff_t, make_signed_t&lt;decltype(c.size())&gt;&gt;;
</pre>
<blockquote>
<p>
<ins>-?- <i>Mandates:</i> <code>decltype(c.size())</code> is an integral or enumeration type
other than <code>bool</code>.</ins>
<p/>
-18- <i>Returns:</i>
<blockquote>
<pre>
static_cast&lt;common_type_t&lt;ptrdiff_t, make_signed_t&lt;decltype(c.size())&gt;&gt;&gt;(c.size())
</pre>
</blockquote>
</p>
</blockquote>
</blockquote>
</li>

</ol>
</blockquote>

<p><i>[2019-11-18; Casey comments and improves wording]</i></p>

<p>
It would be better to provided the <i>Mandates:</i> guarantee in [tab:meta.trans.sign] instead of
one special place where the <code>make_signed</code> template is used. The wording below attempts to 
realize that.
</p>

<p><i>[2019-11-23 Issue Prioritization]</i></p>

<p>Status to Tentatively Ready after five positive votes on the reflector.</p>


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

<ol>
<li><p>Change Table 52 &mdash; "Sign modifications" in  [tab:meta.trans.sign] as indicated:</p>

<table border="1">
<caption>Table 52 &mdash; Sign modifications [tab:meta.trans.sign]</caption>
<tr>
<th>Template</th>
<th>Comments</th>
</tr> 

<tr>
<td>
<code>template &lt;class T&gt;<br/>
struct make_signed;</code>
</td>
<td>
If <code>T</code> names a (possibly <i>cv</i>-qualified) signed integer type (6.9.2 <a href="https://wg21.link/basic.fundamental">[basic.fundamental]</a>) then<br/>
the member typedef <code>type</code> names the type <code>T</code>; otherwise, if <code>T</code> names a<br/>
(possibly <i>cv</i>-qualified) unsigned integer type then <code>type</code> names the<br/>
corresponding signed integer type, with the same <i>cv</i>-qualifiers as <code>T</code>;<br/>
otherwise, <code>type</code> names the signed integer type with smallest<br/>
rank (6.9.6 <a href="https://wg21.link/conv.rank">[conv.rank]</a>) for which <code>sizeof(T) == sizeof(type)</code>, with the same<br/>
<i>cv</i>-qualifiers as <code>T</code>.<br/>
<i><del>Requires</del><ins>Mandates</ins>:</i> <code>T</code> <del>shall be</del><ins>is</ins> a<ins>n</ins> <del>(possibly <i>cv</i>-qualified)</del> integral <del>type</del> or enumeration <ins>type other than <i>cv</i></ins> <del>but not a</del> <code>bool</code> <del>type</del>.
</td>
</tr>

<tr>
<td>
<code>template &lt;class T&gt;<br/>
struct make_unsigned;</code>
</td>
<td>
If <code>T</code> names a (possibly <i>cv</i>-qualified) unsigned integer type (6.9.2 <a href="https://wg21.link/basic.fundamental">[basic.fundamental]</a>) then<br/>
the member typedef <code>type</code> names the type <code>T</code>; otherwise, if <code>T</code> names a<br/>
(possibly <i>cv</i>-qualified) signed integer type then <code>type</code> names the<br/>
corresponding unsigned integer type, with the same <i>cv</i>-qualifiers as <code>T</code>;<br/>
otherwise, <code>type</code> names the unsigned integer type with smallest<br/>
rank (6.9.6 <a href="https://wg21.link/conv.rank">[conv.rank]</a>) for which <code>sizeof(T) == sizeof(type)</code>, with the same<br/>
<i>cv</i>-qualifiers as <code>T</code>.<br/>
<i><del>Requires</del><ins>Mandates</ins>:</i> <code>T</code> <del>shall be</del><ins>is</ins> a<ins>n</ins> <del>(possibly <i>cv</i>-qualified)</del> integral <del>type</del> or enumeration <ins>type other than <i>cv</i></ins> <del>but not a</del> <code>bool</code> <del>type</del>.
</td>
</tr>
</table>

</li>

<li><p>Change 24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class C&gt; constexpr auto ssize(const C&amp; c)
  -&gt; common_type_t&lt;ptrdiff_t, make_signed_t&lt;decltype(c.size())&gt;&gt;;
</pre>
<blockquote>
<p>
-18- <i><del>Returns</del><ins>Effects</ins>:</i> <ins>Equivalent to:</ins>
<blockquote>
<pre>
<ins>return</ins> static_cast&lt;common_type_t&lt;ptrdiff_t, make_signed_t&lt;decltype(c.size())&gt;&gt;&gt;(c.size())<ins>;</ins>
</pre>
</blockquote>
</p>
</blockquote>
</blockquote>
</li>

</ol>





</body>
</html>
