<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2206: Inaccuracy in initializer_list constructor requirements</title>
<meta property="og:title" content="Issue 2206: Inaccuracy in initializer_list constructor requirements">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2206.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#Open">Open</a> status.</em></p>
<h3 id="2206"><a href="lwg-active.html#2206">2206</a>. Inaccuracy in <code>initializer_list</code> constructor requirements</h3>
<p><b>Section:</b> 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a>, 23.2.7 <a href="https://wg21.link/associative.reqmts">[associative.reqmts]</a>, 23.2.8 <a href="https://wg21.link/unord.req">[unord.req]</a>, 29.5.3.2 <a href="https://wg21.link/rand.req.seedseq">[rand.req.seedseq]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Jeffrey Yasskin <b>Opened:</b> 2012-10-21 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#sequence.reqmts">active issues</a> in [sequence.reqmts].</p>
<p><b>View all other</b> <a href="lwg-index.html#sequence.reqmts">issues</a> in [sequence.reqmts].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>

<p>
In 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a> p3, we have "<code>il</code> designates an object of type
<code>initializer_list&lt;value_type&gt;</code>", and then several functions that take
'<code>il</code>' as an argument. However, an expression like <code>{1, 2, 'a'}</code> is <em>not</em>
an object of type <code>initializer_list&lt;int&gt;</code> unless it's used to initialize
an explicitly-typed variable of that type. I believe we want:
</p>
<blockquote><pre>
std::vector&lt;int&gt; v;
v = {1, 2, 'a'};
</pre></blockquote>
<p>
to compile portably, so we should say something different when defining '<code>il</code>'. The 
same phrasing happens in 23.2.7 <a href="https://wg21.link/associative.reqmts">[associative.reqmts]</a>, 23.2.8 <a href="https://wg21.link/unord.req">[unord.req]</a>, and 
29.5.3.2 <a href="https://wg21.link/rand.req.seedseq">[rand.req.seedseq]</a>.
<p/>
This may just be an editorial issue because the actual class synopses declare the functions 
to take <code>initializer_list&lt;exact_type&gt;</code>.
</p>

<p><i>[2013-03-15 Issues Teleconference]</i></p>

<p>
Moved to Open.
</p>
<p>
This is definitely not NAD
</p>
<p>
Should copy the suggested wording as the proposed resolution.
</p>

<p><i>[2019-03-26; Daniel comments and provides wording]</i></p>

<p>
The 2013-03-15 comment is confusing, since it recommends to "copy the suggested wording as the proposed resolution". 
I couldn't find such wording in the issue nor in the associated wiki, so I provided that wording out of myself.
The tricky part is to define which kind of <i>braced-init-list</i> we want to allow. As Tim Song pointed out, we
still need the existing support for <code>std::initializer_list&lt;value_type&gt;</code> as well, because otherwise
existing semantics based on expressions such as <code>li.begin()</code> won't work anymore.
The below suggested wording restricts supported <i>braced-init-list</i>s to every initializer list that can be used 
to copy-list-initialize an object of type <code>std::initializer_list&lt;value_type&gt;</code> by saying:
</p>
<blockquote><p>
"<code>bil</code> designates any <i>braced-init-list</i> suitable to copy-list-initialize an object of type 
<code>initializer_list&lt;value_type&gt;</code> (9.5.5 <a href="https://wg21.link/dcl.init.list">[dcl.init.list]</a>)"
</p></blockquote>
<p>
As a drive-by fix, the provided wording adds another initialization "expression" that makes the construction 
of the form
</p>
<blockquote><pre>
std::vector&lt;int&gt; v = {1, 2, 'a'};
</pre></blockquote>
<p>
valid (We just miss a copy-initialization case).
</p>


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

<blockquote class="note">
<p>
[<i>Drafting note:</i> We need to special-case the "expression" <code>X u = bil;</code> below,
because for empty <i>braced-init-list</i> the effects are those of calling the default 
constructor. &mdash; <i>end drafting note</i>]
</p>
</blockquote>

<ol>
<li><p>Modify 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a> as indicated:</p>

<blockquote>
<p>
-3- In Tables 66 and 67, [&hellip;] <code>il</code> designates a<del>n object</del><ins>value</ins> of type 
<code>initializer_list&lt;value_type&gt;</code>, <ins><code>bil</code> designates any <i>braced-init-list</i> 
suitable to copy-list-initialize an object of type <code>initializer_list&lt;value_type&gt;</code> 
(9.5.5 <a href="https://wg21.link/dcl.init.list">[dcl.init.list]</a>),</ins> [&hellip;]
</p>
</blockquote>

</li>

<li><p>Modify Table 66 &mdash; "Sequence container requirements (in addition to container)" as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 66 &mdash; Sequence container requirements (in addition to container)</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Assertion&#47;note<br/>pre-&#47;post-condition</th>
</tr>
<tr>
<td colspan="3" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>X(il)</code><br/>
<ins><code>X u = il;</code></ins>
</td>
<td><code></code></td>
<td>
Equivalent to <code>X(il.begin(), il.end())</code><br/>
<ins>or <code>X u(il.begin(), il.end());</code>, respectively</ins>
</td>
</tr>
<tr>
<td>
<ins><code>X(bil)</code></ins>
</td>
<td><code></code></td>
<td>
<ins>Equivalent to <code>X(initializer_list&lt;value_type&gt;(bil))</code></ins>
</td>
</tr>
<tr>
<td>
<ins><code>X u = bil;</code></ins>
</td>
<td><code></code></td>
<td>
<ins>If <code>bil</code> is empty, equivalent to <code>X u;</code>, otherwise<br/>
equivalent to <code>X u = initializer_list&lt;value_type&gt;(bil);</code></ins>
</td>
</tr>
<tr>
<td>
<code>a = il</code>
</td>
<td><code>X&amp;</code></td>
<td>
[&hellip;]
</td>
</tr>
<tr>
<td>
<ins><code>a = bil</code></ins>
</td>
<td><ins><code>X&amp;</code></ins></td>
<td>
<ins>Equivalent to <code>a = initializer_list&lt;value_type&gt;(bil)</code></ins>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>a.insert(p, il)</code>
</td>
<td><code>iterator</code></td>
<td>
[&hellip;]
</td>
</tr>
<tr>
<td>
<ins><code>a.insert(p, bil)</code></ins>
</td>
<td><ins><code>iterator</code></ins></td>
<td>
<ins>Equivalent to <code>a.insert(p, initializer_list&lt;value_type&gt;(bil))</code></ins>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>a.assign(il)</code>
</td>
<td><code>void</code></td>
<td>
[&hellip;]
</td>
</tr>
<tr>
<td>
<ins><code>a.assign(bil)</code></ins>
</td>
<td><ins><code>void</code></ins></td>
<td>
<ins>Equivalent to <code>a.assign(initializer_list&lt;value_type&gt;(bil))</code></ins>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<code>[&hellip;]</code>
</td>
</tr>
</table>
</blockquote>

</li>

<li><p>Modify 23.2.7 <a href="https://wg21.link/associative.reqmts">[associative.reqmts]</a> as indicated:</p>

<blockquote>
<p>
-8- In Table 69, [&hellip;] <code>il</code> designates a<del>n object</del><ins>value</ins> of type 
<code>initializer_list&lt;value_type&gt;</code>, <ins><code>bil</code> designates any <i>braced-init-list</i> 
suitable to copy-list-initialize an object of type <code>initializer_list&lt;value_type&gt;</code> 
(9.5.5 <a href="https://wg21.link/dcl.init.list">[dcl.init.list]</a>),</ins> [&hellip;]
</p>
</blockquote>

</li>

<li><p>Modify Table 69 &mdash; "Associative container requirements (in addition to container)" as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 69 &mdash; Associative container requirements (in addition to container)</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Assertion&#47;note<br/>pre-&#47;post-condition</th>
<th>Complexity</th>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>X(il)</code><br/>
<ins><code>X u = il;</code></ins>
</td>
<td><code></code></td>
<td>
same as <code>X(il.begin(), il.end())</code><br/>
<ins>or <code>X u(il.begin(), il.end());</code>, respectively</ins>
</td>
<td>
same as <code>X(il.begin(), il.end())</code><br/>
<ins>or <code>X u(il.begin(), il.end());</code>, respectively</ins>
</td>
</tr>
<tr>
<td>
<ins><code>X(bil)</code></ins>
</td>
<td><code></code></td>
<td>
<ins>Equivalent to <code>X(initializer_list&lt;value_type&gt;(bil))</code></ins>
</td>
<td></td>
</tr>
<tr>
<td>
<ins><code>X u = bil;</code></ins>
</td>
<td><code></code></td>
<td>
<ins>If <code>bil</code> is empty, equivalent to <code>X u;</code>, otherwise<br/>
equivalent to <code>X u = initializer_list&lt;value_type&gt;(bil);</code></ins>
</td>
<td></td>
</tr>
<tr>
<td>
<code>X(il,c)</code>
</td>
<td><code></code></td>
<td>
same as <code>X(il.begin(), il.end(), c)</code>
</td>
<td>
same as <code>X(il.begin(), il.end(), c)</code>
</td>
</tr>
<tr>
<td>
<ins><code>X(bil, c)</code></ins>
</td>
<td><code></code></td>
<td>
<ins>Equivalent to <code>X(initializer_list&lt;value_type&gt;(bil), c)</code></ins>
</td>
<td></td>
</tr>
<tr>
<td>
<code>a = il</code>
</td>
<td><code>X&amp;</code></td>
<td>
[&hellip;]
</td>
<td>
[&hellip;]
</td>
</tr>
<tr>
<td>
<ins><code>a = bil</code></ins>
</td>
<td><ins><code>X&amp;</code></ins></td>
<td>
<ins>Equivalent to <code>a = initializer_list&lt;value_type&gt;(bil)</code></ins>
</td>
<td></td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>a.insert(il)</code>
</td>
<td><code>void</code></td>
<td>
equivalent to <code>a.insert(il.begin(), il.end())</code>
</td>
<td></td>
</tr>
<tr>
<td>
<ins><code>a.insert(bil)</code></ins>
</td>
<td><ins><code>void</code></ins></td>
<td>
<ins>Equivalent to <code>a.insert(initializer_list&lt;value_type&gt;(bil))</code></ins>
</td>
<td></td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>a.assign(il)</code>
</td>
<td><code>void</code></td>
<td>
[&hellip;]
</td>
</tr>
<tr>
<td>
<ins><code>a.assign(bil)</code></ins>
</td>
<td><ins><code>void</code></ins></td>
<td>
<ins>Equivalent to <code>a.assign(initializer_list&lt;value_type&gt;(bil))</code></ins>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
</table>
</blockquote>

</li>

<li><p>Modify 23.2.8 <a href="https://wg21.link/unord.req">[unord.req]</a> p11's bullet list as indicated:</p>

<blockquote>
<p>
-11- In Table 70:
</p>
<ol style="list-style-type: none">
<li><p>(11.1) &mdash; [&hellip;]</p></li>
<li><p>[&hellip;]</p></li>
<li><p>(11.14) &mdash; <code>il</code> denotes a value of type <code>initializer_list&lt;value_type&gt;</code>,</p></li>
<li><p><ins>(11.?) &mdash; <code>bil</code> denotes any <i>braced-init-list</i> suitable to copy-list-initialize 
an object of type <code>initializer_list&lt;value_type&gt;</code> (9.5.5 <a href="https://wg21.link/dcl.init.list">[dcl.init.list]</a>), </ins></p></li>
<li><p>[&hellip;]</p></li>
</ol>
</blockquote>

</li>

<li><p>Modify Table 70 &mdash; "Unordered associative container requirements (in addition to container)" as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> There is a preexisting issue with Table 70, that there is no symbol <code>u</code> specified
("<code>u</code> denotes the name of a variable being declared"), so existing initialization forms with a named
variable are currently always written as "<code>X a[&hellip;]</code>" where <code>a</code> is defined as "<code>a</code> denotes a 
value of type <code>X</code>", the wording below follows this existing practice but the author of this wording would 
like to kindly ask the Project Editor to introduce said symbol <code>u</code> and apply it to all existing and new such 
named initialization forms instead. &mdash; <i>end drafting note</i>]
</p>
</blockquote>

<blockquote>
<table border="1">
<caption>Table 70 &mdash; Unordered associative container requirements (in addition to container)</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Assertion&#47;note<br/>pre-&#47;post-condition</th>
<th>Complexity</th>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>X(il)</code><br/>
<ins><code>X a = il;</code></ins>
</td>
<td><code>X</code></td>
<td>
Same as <code>X(il.begin(), il.end())</code><br/>
<ins>or <code>X a(il.begin(), il.end());</code>, respectively</ins>
</td>
<td>
Same as <code>X(il.begin(), il.end())</code><br/>
<ins>or <code>X a(il.begin(), il.end());</code>, respectively</ins>
</td>
</tr>
<tr>
<td>
<ins><code>X(bil)</code></ins>
</td>
<td><ins><code>X</code></ins></td>
<td>
<ins>Equivalent to <code>X(initializer_list&lt;value_type&gt;(bil))</code></ins>
</td>
<td></td>
</tr>
<tr>
<td>
<ins><code>X a = bil;</code></ins>
</td>
<td><ins><code>X</code></ins></td>
<td>
<ins>If <code>bil</code> is empty, equivalent to <code>X a;</code>, otherwise<br/>
equivalent to <code>X a = initializer_list&lt;value_type&gt;(bil);</code></ins>
</td>
<td></td>
</tr>
<tr>
<td>
<code>X(il, n)</code>
</td>
<td><code>X</code></td>
<td>
Same as <code>X(il.begin(), il.end(), n)</code>
</td>
<td>
Same as <code>X(il.begin(), il.end(), n)</code>
</td>
</tr>
<tr>
<td>
<ins><code>X(bil, n)</code></ins>
</td>
<td><ins><code>X</code></ins></td>
<td>
<ins>Equivalent to <code>X(initializer_list&lt;value_type&gt;(bil), n)</code></ins>
</td>
<td></td>
</tr>
<tr>
<td>
<code>X(il, n, hf)</code>
</td>
<td><code>X</code></td>
<td>
Same as <code>X(il.begin(), il.end(), n, hf)</code>
</td>
<td>
Same as <code>X(il.begin(), il.end(), n, hf)</code>
</td>
</tr>
<tr>
<td>
<ins><code>X(bil, n, hf)</code></ins>
</td>
<td><ins><code>X</code></ins></td>
<td>
<ins>Equivalent to <code>X(initializer_list&lt;value_type&gt;(bil), n, hf)</code></ins>
</td>
<td></td>
</tr>
<tr>
<td>
<code>X(il, n, hf, eq)</code>
</td>
<td><code>X</code></td>
<td>
Same as <code>X(il.begin(), il.end(), n, hf, eq)</code>
</td>
<td>
Same as <code>X(il.begin(), il.end(), n, hf, eq)</code>
</td>
</tr>
<tr>
<td>
<ins><code>X(bil, n, hf, eq)</code></ins>
</td>
<td><ins><code>X</code></ins></td>
<td>
<ins>Equivalent to <code>X(initializer_list&lt;value_type&gt;(bil), n, hf, eq)</code></ins>
</td>
<td></td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>a = il</code>
</td>
<td><code>X&amp;</code></td>
<td>
[&hellip;]
</td>
<td>
[&hellip;]
</td>
</tr>
<tr>
<td>
<ins><code>a = bil</code></ins>
</td>
<td><ins><code>X&amp;</code></ins></td>
<td>
<ins>Equivalent to <code>a = initializer_list&lt;value_type&gt;(bil)</code></ins>
</td>
<td></td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>a.insert(il)</code>
</td>
<td><code>void</code></td>
<td>
Same as <code>a.insert(il.begin(), il.end())</code>.
</td>
<td>
Same as <code>a.insert(il.begin(), il.end())</code>.
</td>
</tr>
<tr>
<td>
<ins><code>a.insert(bil)</code></ins>
</td>
<td><ins><code>void</code></ins></td>
<td>
<ins>Equivalent to <code>a.insert(initializer_list&lt;value_type&gt;(bil))</code></ins>
</td>
<td></td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
</table>
</blockquote>

</li>

<li><p>Modify 29.5.3.2 <a href="https://wg21.link/rand.req.seedseq">[rand.req.seedseq]</a> p2's bullet list as indicated:</p>

<blockquote>
<p>
-2- A class <code>S</code> satisfies the requirements of a seed sequence if the expressions shown in Table 82 are 
valid and have the indicated semantics, and [&hellip;] In that Table and throughout this subclause:
</p>
<ol style="list-style-type: none">
<li><p>(2.1) &mdash; [&hellip;]</p></li>
<li><p><ins>(2.?) &mdash; <code>u</code> denotes the name of a variable being declared,</ins></p></li>
<li><p>[&hellip;]</p></li>
<li><p>(2.6) &mdash; <code>il</code> is a value of <code>initializer_list&lt;T&gt;</code><del>.</del><ins>;</ins></p></li>
<li><p><ins>(2.?) &mdash; <code>bil</code> denotes any <i>braced-init-list</i> suitable to 
copy-list-initialize an object of type <code>initializer_list&lt;T&gt;</code> 
(9.5.5 <a href="https://wg21.link/dcl.init.list">[dcl.init.list]</a>).</ins></p></li>
</ol>
</blockquote>

</li>

<li><p>Modify Table 82 &mdash; "Seed sequence requirements" as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 82 &mdash; Seed sequence requirements</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Pre&#47;post-condition</th>
<th>Complexity</th>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>S(il)</code><br/>
<ins><code>S u = il;</code></ins>
</td>
<td></td>
<td>
Same as <code>S(il.begin(), il.end())</code><br/>
<ins>or <code>S u(il.begin(), il.end());</code>, respectively</ins>
</td>
<td>
same as <code>S(il.begin(), il.end())</code><br/>
<ins>or <code>S u(il.begin(), il.end());</code>, respectively</ins>
</td>
</tr>
<tr>
<td>
<ins><code>S(bil)</code></ins>
</td>
<td></td>
<td>
<ins>Equivalent to <code>S(initializer_list&lt;T&gt;(bil))</code></ins>
</td>
<td></td>
</tr>
<tr>
<td>
<ins><code>S u = bil;</code></ins>
</td>
<td></td>
<td>
<ins>If <code>bil</code> is empty, equivalent to <code>S u;</code>, otherwise<br/>
equivalent to <code>S u = initializer_list&lt;T&gt;(bil);</code></ins>
</td>
<td></td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
</table>
</blockquote>

</li>

</ol>





</body>
</html>
