<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3875: std::ranges::repeat_view&lt;T, IntegerClass&gt;::iterator may be ill-formed</title>
<meta property="og:title" content="Issue 3875: std::ranges::repeat_view&lt;T, IntegerClass&gt;::iterator may be ill-formed">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3875.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++23">C++23</a> status.</em></p>
<h3 id="3875"><a href="lwg-defects.html#3875">3875</a>. <code>std::ranges::repeat_view&lt;T, IntegerClass&gt;::<i>iterator</i></code> may be ill-formed</h3>
<p><b>Section:</b> 25.6.5 <a href="https://wg21.link/range.repeat">[range.repeat]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2023-02-05 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
25.6.5.3 <a href="https://wg21.link/range.repeat.iterator">[range.repeat.iterator]</a> specifies <code>difference_type</code> as
</p>
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
<pre>
using difference_type = conditional_t&lt;<i>is-signed-integer-like</i>&lt;<i>index-type</i>&gt;,
  <i>index-type</i>,
  <i>IOTA-DIFF-T</i>(<i>index-type</i>)&gt;;
</pre>
</blockquote>
<p>
which always instantiates <code><i>IOTA-DIFF-T</i>(<i>index-type</i>)</code>, and thus possibly makes the program ill-formed when 
<code>index-type</code> is an integer-class type (<code><i>index-type</i></code> is same as <code>Bound</code> in this case), because 
<code><i>IOTA-DIFF-T</i>(<i>index-type</i>)</code> is specified to be <code>iter_difference_t&lt;<i>index-type</i>&gt;</code> 
which may be ill-formed (25.6.4.2 <a href="https://wg21.link/range.iota.view">[range.iota.view]</a>/1.1).
<p/>
I think the intent is using <code><i>index-type</i></code> as-is without instantiating <code><i>IOTA-DIFF-T</i></code> when 
<code><i>is-signed-integer-like</i>&lt;<i>index-type</i>&gt;</code> is <code>true</code>.
<p/>
However, when <code>Bound</code> is an unsigned integer-class type, it's unclear which type should the difference type be, 
or whether <code>repeat_view</code> should be well-formed when the possibly intended <code><i>IOTA-DIFF-T</i>(Bound)</code> is ill-formed.
</p>
<p><i>[2023-02-09 Tim adds wording]</i></p>

<p>We should reject types for which there is no usable difference type.</p>

<p><i>[Issaquah 2023-02-09; LWG]</i></p>

<p>Move to Immediate for C++23</p>

<p><i>[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate &rarr; WP.]</i></p>



<p id="res-3875"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4928" title=" Working Draft, Standard for Programming Language C++">N4928</a>.
</p>

<ol>
<li><p>Modify 25.2 <a href="https://wg21.link/ranges.syn">[ranges.syn]</a>, header <code>&lt;ranges&gt;</code> synopsis, as indicated:</p>
<blockquote>
<pre>
// [&hellip;]
namespace std::ranges {
  template&lt;move_constructible W, semiregular Bound = unreachable_sentinel_t&gt;
    requires <ins><i>see below</i></ins><del>(is_object_v&lt;W> &amp;&amp; same_as&lt;W, remove_cv_t&lt;W&gt;&gt; &amp;&amp;
              (<i>is-integer-like</i>&lt;Bound> || same_as&lt;Bound, unreachable_sentinel_t&gt;))</del>
  class repeat_view;
</pre>
</blockquote>
</li>

<li><p>Modify 25.6.5.2 <a href="https://wg21.link/range.repeat.view">[range.repeat.view]</a> as indicated:</p>
<blockquote>
<pre>
namespace std::ranges {
  
<ins>  template&lt;class T&gt;
  concept <i>integer-like-with-usable-difference-type</i> =   //<i>exposition only</i>
    <i>is-signed-integer-like</i>&lt;T> || (<i>is-integer-like</i>&lt;T> &amp;&amp; weakly_incrementable&lt;T>);</ins>

  template&lt;move_constructible W, semiregular Bound = unreachable_sentinel_t&gt;
    requires (is_object_v&lt;W> &amp;&amp; same_as&lt;W, remove_cv_t&lt;W&gt;&gt; &amp;&amp;
              (<i><del>is-integer-like</del><ins>integer-like-with-usable-difference-type</ins></i>&lt;Bound> || same_as&lt;Bound, unreachable_sentinel_t&gt;))
  class repeat_view {
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li><p>Modify 25.6.5.3 <a href="https://wg21.link/range.repeat.iterator">[range.repeat.iterator]</a> as indicated:</p>
<blockquote>
<pre>
namespace std::ranges {
  template&lt;move_constructible W, semiregular Bound<del> = unreachable_sentinel_t</del>&gt;
    requires (is_object_v&lt;W> &amp;&amp; same_as&lt;W, remove_cv_t&lt;W&gt;&gt; &amp;&amp;
              (<i><del>is-integer-like</del><ins>integer-like-with-usable-difference-type</ins></i>&lt;Bound> || same_as&lt;Bound, unreachable_sentinel_t&gt;))
  class repeat_view&lt;W, Bound>::<i>iterator</i> {
  private:
    using <i>index-type</i> =                  <i>// exposition only</i>
      conditional_t&lt;same_as&lt;Bound, unreachable_sentinel_t&gt;, ptrdiff_t, Bound&gt;;
    [&hellip;]
  public:
    [&hellip;]
    using difference_type = <ins><i>see below</i></ins><del>conditional_t&lt;<i>is-signed-integer-like</i>&lt;<i>index-type</i>&gt;,
        <i>index-type</i>,
        <i>IOTA-DIFF-T</i>(<i>index-type</i>)></del>;
    [&hellip;]
  };
}
</pre>
</blockquote>
<p>
<ins>-?- If <code><i>is-signed-integer-like</i>&lt;<i>index-type</i>&gt;</code> is <code>true</code>,
the member <i>typedef-name</i> <code>difference_type</code> denotes <code><i>index-type</i></code>.
Otherwise, it denotes <code><i>IOTA-DIFF-T</i>(<i>index-type</i>)</code> 
(25.6.4.2 <a href="https://wg21.link/range.iota.view">[range.iota.view]</a>).</ins>
</p>
</li>
</ol>






</body>
</html>
