<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2137</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="2137"></A><H4>2137.
  
List-initialization from object of same type
</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>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2015-06-10<BR>


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



<P>It is not clear in code like the following that selecting
a copy/move constructor is the correct choice when an
initializer list contains a single element of the type
being initialized, as required by <A HREF="1467.html">issue 1467</A>:</P>

<PRE>
  #include &lt;initializer_list&gt;
  #include &lt;iostream&gt;

  struct Q {
    Q() { std::cout &lt;&lt; "default\n"; }
    Q(Q const&amp;) { std::cout &lt;&lt; "copy\n"; }
    Q(Q&amp;&amp;) { std::cout &lt;&lt; "move\n"; }
    Q(std::initializer_list&lt;Q&gt;) { std::cout &lt;&lt; "initializer list\n"; }
  };

  int main() {
    Q x = Q { Q() };
  }
</PRE>

<P>Here the intent is that <TT>Q</TT> objects can contain
other <TT>Q</TT> objects, but this is broken by the
resolution of <A HREF="1467.html">issue 1467</A>.</P>

<P>Perhaps the presence of an initializer-list constructor
should change the outcome?</P>

<P><B>Proposed resolution (April, 2016):</B></P>

<OL>
<LI><P>Change 9.5.5 [<A href="https://wg21.link/dcl.init.list#3.1">dcl.init.list</A>] bullet 3.1 as follows:</P></LI>

<BLOCKQUOTE>

List-initialization of an object or reference of
type <TT>T</TT> is defined as follows:

<UL>
<LI>

<P>If <TT>T</TT> is <DEL>a class type</DEL> <INS>an
aggregate class</INS> and the initializer list has a single
element of type <I>cv</I> <TT>U</TT>, where <TT>U</TT>
is <TT>T</TT> or a class derived from
<TT>T</TT>, the object is initialized from that element (by
copy-initialization for copy-list-initialization, or by
direct-initialization for
direct-list-initialization).</P>
</LI>

<LI><P>...</P></LI>

</UL>

</BLOCKQUOTE>

<LI><P>Change 12.2.4.2.6 [<A href="https://wg21.link/over.ics.list#2">over.ics.list</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

If the parameter type is <DEL>a</DEL> <INS>an
aggregate</INS> class <TT>X</TT> and the initializer list
has a single element of type <I>cv</I> <TT>U</TT>,
where <TT>U</TT> is <TT>X</TT> or a class derived
from <TT>X</TT>, the implicit conversion sequence is the one
required to convert the element to the parameter type.

</BLOCKQUOTE>

<LI><P>Change 12.2.4.2.6 [<A href="https://wg21.link/over.ics.list#6">over.ics.list</A>] paragraph 6 as
follows, breaking the existing running text into a bulleted list:</P></LI>

<BLOCKQUOTE>

<P>Otherwise, if the parameter is a non-aggregate
class <TT>X</TT> and overload resolution per
12.2.2.8 [<A href="https://wg21.link/over.match.list">over.match.list</A>] chooses a single best
constructor <INS><TT>C</TT></INS> of <TT>X</TT> to perform
the initialization of an object of type <TT>X</TT> from the
argument initializer <DEL>list,</DEL> <INS>list:</INS>
</P>

<UL>
<LI><P><INS>If <TT>C</TT> is not an initializer-list
constructor and the initializer list has a single element of
type <I>cv</I> <TT>U</TT>, where <TT>U</TT> is <TT>X</TT> or
a class derived from <TT>X</TT>, the implicit conversion
sequence has Exact Match rank if <TT>U</TT> is <TT>X</TT>,
or Conversion rank if <TT>U</TT> is derived
from <TT>X</TT></INS></P></LI>

<LI>

<P>
<INS>Otherwise,</INS> the implicit conversion sequence is a user-defined
conversion sequence with the second standard conversion
sequence an identity conversion.</P>
</LI>

</UL>

<P>If multiple constructors are viable...</P>

</BLOCKQUOTE>

</OL>

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