<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 632</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="632"></A><H4>632.
  
Brace-enclosed initializer for scalar member of aggregate
</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>CD1
 &#160;&#160;&#160;

 <B>Submitter: </B>Greg Comeau
 &#160;&#160;&#160;

 <B>Date: </B>3 May 2007<BR>


<P>[Voted into the WP at the June, 2008 meeting as part of paper N2672.]</P>

<P>C (both C90 and C99) appear to allow a declaration of the form</P>

<PRE>
    struct S { int i; } s = { { 5 } };
</PRE>

<P>in which the initializer of a scalar member of an aggregate can
itself be brace-enclosed.  The relevant wording from the C99
Standard is found in 6.7.8 paragraph 11:</P>

<BLOCKQUOTE>

The initializer for a scalar shall be a single expression,
optionally enclosed in braces.

</BLOCKQUOTE>

<P>and paragraph 16:</P>

<BLOCKQUOTE>

Otherwise, the initializer for an object that has aggregate or
union type shall be a brace-enclosed list of initializers for the
elements or named members.

</BLOCKQUOTE>

<P>The &#8220;list of initializers&#8221; in paragraph 16 must be
a recursive reference to paragraph 11 (that's the only place that
describes how an initialized item gets its value from the
initializer expression), which would thus make the
&#8220;brace-enclosed&#8221; part of paragraph 11 apply to each of
the initializers in the list in paragraph 16 as well.</P>

<P>This appears to be an incompatibility between C and C++:
9.5.2 [<A href="https://wg21.link/dcl.init.aggr#11">dcl.init.aggr</A>] paragraph 11 says,</P>

<BLOCKQUOTE>

If the <I>initializer-list</I> begins with a left brace, then the
succeeding comma-separated list of <I>initializer-clause</I>s
initializes the members of a subaggregate....

</BLOCKQUOTE>

<P>which clearly leaves the impression that only a subaggregate
may be initialized by a brace-enclosed <I>initializer-clause</I>.</P>

<P>Either the specification in 9.5.2 [<A href="https://wg21.link/dcl.init.aggr">dcl.init.aggr</A>]
should be changed to allow a brace-enclosed initializer of a
scalar member of an aggregate, as in C, or this incompatibility
should be listed in Appendix Clause Annex C [<A href="https://wg21.link/diff">diff</A>].</P>

<P><B>Notes from the July, 2007 meeting:</B></P>

<P>It was noted that implementations differ in their handling of this
construct; however, the issue is long-standing and fairly obscure.</P>

<P><B>Notes from the October, 2007 meeting:</B></P>

<P>The initializer-list proposal will resolve this issue when it is
adopted.</P>

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