<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1599</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="1599"></A><H4>1599.
  
Lifetime of <TT>initializer_list</TT> underlying array
</H4>
<B>Section: </B>9.5.5&#160; [<A href="https://wg21.link/dcl.init.list">dcl.init.list</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD4
 &#160;&#160;&#160;

 <B>Submitter: </B>Johannes Schaub
 &#160;&#160;&#160;

 <B>Date: </B>2012-02-10<BR>


<P>[Adopted as paper P0135R1 at the June, 2016 meeting.]</P>



<P>The normative wording of 9.5.5 [<A href="https://wg21.link/dcl.init.list">dcl.init.list</A>] regarding the
lifetime of the array underlying an <TT>initializer_list</TT> object
does not match the intent as specified in the example in paragraph 6
of that section, even after application of the resolution of
<A HREF="1290.html">issue 1290</A>.  That example contains the
lines:</P>

<PRE>
  void f() {
    std::initializer_list&lt;int&gt; i3 = { 1, 2, 3 };
  }
</PRE>

<P>The commentary indicates that the lifetime of the array created
for the initialization of <TT>i3</TT> &#8220;persists for the lifetime
of the variable.&#8221;  However, that is not the effect of the
normative wording.  According to paragraph 3,</P>

<BLOCKQUOTE>

if <TT>T</TT> is a specialization of
<TT>std::initializer_list&lt;E&gt;</TT>, an <TT>initializer_list</TT>
object is constructed as described below and used to initialize the
object according to the rules for initialization of an object from a
class of the same type (9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>]).
</BLOCKQUOTE>

<P>In other words, the underlying array for <TT>{1,2,3}</TT> in
the example is associated with the temporary and shares its lifetime;
its lifetime is not extended to that of the variable.</P>

<P>(See also <A HREF="1565.html">issue 1565</A>.)</P>



<P><B>Notes from the February, 2014 meeting:</B></P>

<P>The resolution of <A HREF="1299.html">issue 1299</A>, clarifying
the relationship between temporary expressions and temporary objects, is
relevant to this issue.</P>

<BR><BR>
</BODY>
</HTML>
