<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2432: initializer_list assignability</title>
<meta property="og:title" content="Issue 2432: initializer_list assignability">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2432.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#NAD">NAD</a> status.</em></p>
<h3 id="2432"><a href="lwg-closed.html#2432">2432</a>. <code>initializer_list</code> assignability</h3>
<p><b>Section:</b> 17.11 <a href="https://wg21.link/support.initlist">[support.initlist]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> David Krauss <b>Opened:</b> 2014-09-30 <b>Last modified:</b> 2023-11-13</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#support.initlist">active issues</a> in [support.initlist].</p>
<p><b>View all other</b> <a href="lwg-index.html#support.initlist">issues</a> in [support.initlist].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<code>std::initializer_list::operator=</code> 17.11 <a href="https://wg21.link/support.initlist">[support.initlist]</a> is horribly broken and it needs deprecation:
</p>
<blockquote><pre>
std::initializer_list&lt;foo&gt; a = {{1}, {2}, {3}};
a = {{4}, {5}, {6}};
// New sequence is already destroyed.
</pre></blockquote>
<p>
Assignability of <code>initializer_list</code> isn't explicitly specified, but most implementations supply a default assignment 
operator. I'm not sure what 16.3 <a href="https://wg21.link/description">[description]</a> says, but it probably doesn't matter.
</p>

<p><i>[Lenexa 2015-05-05: Send to EWG as discussed in Telecon]</i></p>


<p><i>[2022-08-24; Reflector poll]</i></p>

<p>
Set status to Tentatively NAD after reflector poll in October 2021.
</p>
<p>
"If somebody wants to revisit it, they'll need to write a paper to demonstrate
what the change would break, whether that would be a problem in practice,
and convince the evolution groups to make a change. But it's not an LWG issue."
</p>

<p><i>[2022-11-25; see <a href="https://github.com/cplusplus/papers/issues/1369">EWG 1369</a>]</i></p>


<p><i>[2022-11-30 LWG telecon. Status changed: Tentatively NAD &rarr; NAD.]</i></p>


<p><i>[Varna 2023-06-12; EWG discussed the issue again]</i></p>

<p>
EWG consensus:
"Send LWG2432 back to LWG to encourage them to either add a note for their
implementer to issue a warning as QoI, or to use the tools
(explicit convertible_to operator=) at their disposal to accomplish their goal"
</p>
<p>
The <code>operator=</code> suggestion refers to:
<pre><code>
initializer_list&amp; operator=(convertible_to&lt;initializer_list&gt; auto&amp;&amp; rhs) { /* ... */ }
initializer_list&amp; operator=(initializer_list const&amp;) requires false = default;
</code></pre>
</p>



<p id="res-2432"><b>Proposed resolution:</b></p>

<ol>
<li><p>Edit 17.11 <a href="https://wg21.link/support.initlist">[support.initlist]</a> p1, class template <code>initializer_list</code> synopsis, as indicated:</p>

<blockquote>
<pre>
namespace std {
  template&lt;class E&gt; class initializer_list {
  public:
    [&hellip;]
    constexpr initializer_list() noexcept;
  
    <ins>initializer_list(const initializer_list&amp;) = default;</ins>
    <ins>initializer_list(initializer_list&amp;&amp;) = default;</ins>
    <ins>initializer_list&amp; operator=(const initializer_list&amp;) = delete;</ins>
    <ins>initializer_list&amp; operator=(initializer_list&amp;&amp;) = delete;</ins>
    
    constexpr size_t size() const noexcept;
    [&hellip;]
  };
  [&hellip;]
}
</pre>
</blockquote>

</li>
</ol>






</body>
</html>
