<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1622</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="1622"></A><H4>1622.
  
Empty aggregate initializer for union
</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++17
 &#160;&#160;&#160;

 <B>Submitter: </B>Daveed Vandevoorde
 &#160;&#160;&#160;

 <B>Date: </B>2013-02-14<BR>


<P>[Adopted at the February/March, 2017 meeting.]</P>

<P>According to 9.5.2 [<A href="https://wg21.link/dcl.init.aggr#15">dcl.init.aggr</A>] paragraph 15,</P>

<BLOCKQUOTE>

When a union is initialized with a brace-enclosed initializer, the braces
shall only contain an <I>initializer-clause</I> for the first non-static
data member of the union.

</BLOCKQUOTE>

<P>This would appear to preclude using <TT>{}</TT> as the initializer for a
union, which would otherwise have reasonable semantics.  Is there a reason
for this restriction?</P>

<P>Also, paragraph 7 reads,</P>

<BLOCKQUOTE>

If there are fewer <I>initializer-clause</I>s in the list than there are
members in the aggregate, then each member not explicitly initialized shall
be initialized from an empty initializer list (9.5.5 [<A href="https://wg21.link/dcl.init.list">dcl.init.list</A>]).

</BLOCKQUOTE>

<P>There should presumably be special treatment for unions, so that only
a single member is initialized in such cases.</P>

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

<P><B>Proposed resolution (November, 2016) [SUPERSEDED]:</B></P>

<P>Change 9.5.2 [<A href="https://wg21.link/dcl.init.aggr#8">dcl.init.aggr</A>] paragraph 8 as follows:</P>

<BLOCKQUOTE>

<P>
<DEL>If there are fewer <I>initializer-clause</I>s in the list than there are
elements in the aggregate, then each</DEL> <INS>Each non-variant</INS>
element <INS>of the aggregate that is</INS>
not explicitly initialized
<DEL>shall be</DEL> <INS>is</INS>
initialized from its default member initializer
(11.4 [<A href="https://wg21.link/class.mem">class.mem</A>]) or, if there is no default member initializer,
<INS>copy-initialized</INS>
from an empty initializer list
(9.5.5 [<A href="https://wg21.link/dcl.init.list">dcl.init.list</A>]). <INS>If the aggregate is a union
and the initializer list is empty, then</INS>
</P>

<UL>
<LI><P><INS>if any union member has a default member initilizer, that
member is initialized from its default member initializer;</INS></P></LI>

<LI><P><INS>otherwise, the first member of the union (if any) is
copy-initialized from an empty initializer list.</INS></P></LI>

</UL>

<P>[<I>Example:</I>...</P>

</BLOCKQUOTE>

<P><B>Proposed resolution (February, 2017):</B></P>

<P>The resolution of <A HREF="2272.html">issue 2272</A> also resolves
this issue.</P>

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