<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2619</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="2619"></A><H4>2619.
  
Kind of initialization for a <I>designated-initializer-list</I>
</H4>
<B>Section: </B>9.5.2&#160; [<A href="https://wg21.link/dcl.init.aggr">dcl.init.aggr</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++23
 &#160;&#160;&#160;

 <B>Submitter: </B>Jim X
 &#160;&#160;&#160;

 <B>Date: </B>2022-07-13<BR>


<P>[Accepted as a DR at the November, 2022 meeting.]</P>

<P>Consider:</P>

<PRE>
struct S {
  explicit S(int){}
};
struct A {
  S s;
};
struct B {
  union {
    S s;
  };
};
int main() {
  A a1 = {.s{0}};  //<SPAN CLASS="cmnt"> #1</SPAN>
  A a2{.s{0}};     //<SPAN CLASS="cmnt"> #2</SPAN>
  B b1 = {.s{0}};  //<SPAN CLASS="cmnt"> #3</SPAN>
  B b2{.s{0}};     //<SPAN CLASS="cmnt"> #4</SPAN>
}
</PRE>

<P>Subclause 9.5.2 [<A href="https://wg21.link/dcl.init.aggr#4.2">dcl.init.aggr</A>] bullet 4.2 specifies:</P>

<BLOCKQUOTE>

Otherwise, the element is copy-initialized from the
corresponding <I>initializer-clause</I> or is initialized with
the <I>brace-or-equal-initializer</I> of the
corresponding <I>designated-initializer-clause</I>.

</BLOCKQUOTE>

<P>It is unclear what kind of initialization is performed for "is
initialized".  For example, one could imagine that the top-level kind
of initialization is inherited.  On the other hand,
9.5.1 [<A href="https://wg21.link/dcl.init.general#14">dcl.init.general</A>] paragraph 14 specifies:</P>

<BLOCKQUOTE>

The initialization that occurs in the = form of
a <I>brace-or-equal-initializer</I> or condition
(8.5 [<A href="https://wg21.link/stmt.select">stmt.select</A>]), as well as in argument passing, function
return, throwing an exception (14.2 [<A href="https://wg21.link/except.throw">except.throw</A>]), handling an
exception (14.4 [<A href="https://wg21.link/except.handle">except.handle</A>]), and aggregate member
initialization (9.5.2 [<A href="https://wg21.link/dcl.init.aggr">dcl.init.aggr</A>]), is
called <I>copy-initialization</I>.

</BLOCKQUOTE>

<P>There is implementation divergence: gcc and icc reject the example; clang and
MSVC accept.</P>

<P><U>Suggested resolution [SUPERSEDED]:</U></P>

<OL>
<LI>
<P>Change in 9.5.2 [<A href="https://wg21.link/dcl.init.aggr#4.1">dcl.init.aggr</A>] bullet 4.1 as follows:</P>

<BLOCKQUOTE>

If the element is an anonymous union member and the initializer list
is a brace-enclosed <I>designated-initializer-list</I>, the element is
initialized by the <DEL><I>designated-initializer-list</I></DEL>
<INS><I>braced-init-list</I></INS> <TT>{ D }</TT>, where <TT>D</TT> is
the <I>designated-initializer-clause</I> naming a member of the
anonymous union member.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 9.5.2 [<A href="https://wg21.link/dcl.init.aggr#4.2">dcl.init.aggr</A>] bullet 4.2 as follows:</P>

<BLOCKQUOTE>

Otherwise, the element is copy-initialized from the
corresponding <I>initializer-clause</I> or
is <DEL>initialized</DEL> <INS>copy-initialized or
direct-initialized</INS> with the <I>brace-or-equal-initializer</I> of
the corresponding <I>designated-initializer-clause</I><INS>, according
to the form of the <I>brace-or-equal-initializer</I>
(9.5.1 [<A href="https://wg21.link/dcl.init.general">dcl.init.general</A>])</INS>. ...

</BLOCKQUOTE>
</LI>
</OL>

<P><B>CWG telecon 2022-09-09:</B></P>

<P>The examples #1 to #4 should all be valid, direct-initializing
the <TT>s</TT> member.</P>

<P><B>Proposed resolution (approved by CWG 2022-09-23):</B></P>

<OL>

<LI>
<P>Change in 9.5.1 [<A href="https://wg21.link/dcl.init.general#14">dcl.init.general</A>] paragraph 14 as follows:</P>

<BLOCKQUOTE>

The initialization that occurs in the = form of
a <I>brace-or-equal-initializer</I> or condition
(8.5 [<A href="https://wg21.link/stmt.select">stmt.select</A>]), as well as in argument passing, function
return, throwing an exception (14.2 [<A href="https://wg21.link/except.throw">except.throw</A>]), handling an
exception (14.4 [<A href="https://wg21.link/except.handle">except.handle</A>]), and aggregate member
initialization <INS>other than by
a <I>designated-initializer-clause</I></INS>
(9.5.2 [<A href="https://wg21.link/dcl.init.aggr">dcl.init.aggr</A>]), is called <I>copy-initialization</I>.

</BLOCKQUOTE>

</LI>

<LI>
<P>Change in 9.5.2 [<A href="https://wg21.link/dcl.init.aggr#4.1">dcl.init.aggr</A>] bullet 4.1 as follows:</P>

<BLOCKQUOTE>

If the element is an anonymous union member and the initializer list
is a brace-enclosed <I>designated-initializer-list</I>, the element is
initialized by the <DEL><I>designated-initializer-list</I></DEL>
<INS><I>braced-init-list</I></INS> <TT>{ D }</TT>, where <TT>D</TT> is
the <I>designated-initializer-clause</I> naming a member of the
anonymous union member.

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 9.5.2 [<A href="https://wg21.link/dcl.init.aggr#4.2">dcl.init.aggr</A>] bullet 4.2 as follows:</P>

<BLOCKQUOTE>

Otherwise, the element is copy-initialized from the
corresponding <I>initializer-clause</I> or
is initialized with the <I>brace-or-equal-initializer</I> of
the corresponding <I>designated-initializer-clause</I>.
If that initializer is of the form <I>assignment-expression</I> or
= <I>assignment-expression</I> and a narrowing conversion
(9.5.5 [<A href="https://wg21.link/dcl.init.list">dcl.init.list</A>]) is required to convert the expression,
the program is ill-formed.
<INS>[ Note: If the initialization is
by <I>designated-initializer-clause</I>, its form determines whether
copy-initialization or direct-initialization is performed.-- end
note]</INS>
</BLOCKQUOTE>
</LI>
</OL>

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