<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3876: Default constructor of std::layout_XX::mapping misses precondition</title>
<meta property="og:title" content="Issue 3876: Default constructor of std::layout_XX::mapping misses precondition">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3876.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="3876"><a href="lwg-defects.html#3876">3876</a>. Default constructor of <code>std::layout_<i>XX</i>::mapping</code> misses precondition</h3>
<p><b>Section:</b> 23.7.3.4 <a href="https://wg21.link/mdspan.layout">[mdspan.layout]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Christian Trott <b>Opened:</b> 2023-02-09 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#mdspan.layout">active issues</a> in [mdspan.layout].</p>
<p><b>View all other</b> <a href="lwg-index.html#mdspan.layout">issues</a> in [mdspan.layout].</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>
As shortly discussed during the LWG review of a <code>layout_stride</code> defect, there is currently no protection against 
creating layout mappings with all static extents where the product of those extents exceeds the representable 
value range of the <code>index_type</code>.
<p/>
For example, the following statement does not violate any preconditions or mandates:
</p>
<blockquote><pre>
layout_left::mapping&lt;extents&lt;int, 100000, 100000&gt;&gt; a{};
</pre></blockquote>
<p>
But <code>a.required_span_size()</code> would overflow since the implied span size is 10B and thus exceeds what 
<code>int</code> can represent.
<p/>
This is only a problem for all static extents, since with any dynamic extent in the mix the implied span size is <code>0</code>. 
Hence we can check for this via a mandates check on the class.
<p/>
The paper <a href="https://wg21.link/P2798R0" title=" Fix layout mappings all static extent default constructor">P2798R0</a> has been provided with the proposed wording as shown below.
</p>

<p><i>[Issaquah 2023-02-10; LWG issue processing]</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-3876"><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 23.7.3.4.5.1 <a href="https://wg21.link/mdspan.layout.left.overview">[mdspan.layout.left.overview]</a> as indicated:</p>
<blockquote>
<p>
-2- If <code>Extents</code> is not a specialization of <code>extents</code>, then the program is ill-formed.
<p/>
-3- <code>layout_left::mapping&lt;E&gt;</code> is a trivially copyable type that models <code>regular</code> for each <code>E</code>.
<p/>
<ins>-?- <i>Mandates</i>: If <code>Extents::rank_dynamic() == 0</code> is <code>true</code>, then the size of the multidimensional 
index space <code>Extents()</code> is representable as a value of type <code>typename Extents::index_type</code>.</ins>
</p>
</blockquote>
</li>

<li><p>Modify 23.7.3.4.6.1 <a href="https://wg21.link/mdspan.layout.right.overview">[mdspan.layout.right.overview]</a> as indicated:</p>
<blockquote>
<p>
-2- If <code>Extents</code> is not a specialization of <code>extents</code>, then the program is ill-formed.
<p/>
-3- <code>layout_right::mapping&lt;E&gt;</code> is a trivially copyable type that models <code>regular</code> for each <code>E</code>.
<p/>
<ins>-?- <i>Mandates</i>: If <code>Extents::rank_dynamic() == 0</code> is <code>true</code>, then the size of the multidimensional 
index space <code>Extents()</code> is representable as a value of type <code>typename Extents::index_type</code>.</ins>
</p>
</blockquote>
</li>

<li><p>Modify 23.7.3.4.7.1 <a href="https://wg21.link/mdspan.layout.stride.overview">[mdspan.layout.stride.overview]</a> as indicated:</p>
<blockquote>
<p>
-2- If <code>Extents</code> is not a specialization of <code>extents</code>, then the program is ill-formed.
<p/>
-3- <code>layout_stride::mapping&lt;E&gt;</code> is a trivially copyable type that models <code>regular</code> for each <code>E</code>.
<p/>
<ins>-?- <i>Mandates</i>: If <code>Extents::rank_dynamic() == 0</code> is <code>true</code>, then the size of the multidimensional 
index space <code>Extents()</code> is representable as a value of type <code>typename Extents::index_type</code>.</ins>
</p>
</blockquote>
</li>
</ol>






</body>
</html>
