<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1587</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="1587"></A><H4>1587.
  
<TT>constexpr</TT> initialization and nested anonymous unions
</H4>
<B>Section: </B>9.2.6&#160; [<A href="https://wg21.link/dcl.constexpr">dcl.constexpr</A>]
 &#160;&#160;&#160;

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

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

 <B>Date: </B>2012-11-16<BR>


<P>[Moved to DR at the September, 2013 meeting.]</P>

<P>After the resolution of <A HREF="1359.html">issue 1359</A>, one of
the requirements for <TT>constexpr</TT> constructors is:</P>

<BLOCKQUOTE>

if the class is a non-empty union, or for each non-empty anonymous
union member of a non-union class, exactly one non-static data member
shall be initialized;

</BLOCKQUOTE>

<P>This wording does not appear to handle nested anonymous unions.
For example:</P>

<PRE>
  struct S {
    union {
      union {
        int x = 1;
        float f;
      };
      void *p = nullptr;
    };
  };
</PRE>

<P>Clearly here both <TT>S::x</TT> and <TT>S::p</TT> are initialized,
but that does not appear to violate the new constraint.</P>

<P><B>Additional note (March, 2013):</B></P>

<P>It is not clear whether this example violates 11.5 [<A href="https://wg21.link/class.union#5">class.union</A>] paragraph 5:
</P>

<BLOCKQUOTE>

The <I>member-specification</I> of an anonymous union shall only define
non-static data members. [<I>Note:</I> Nested types and functions cannot be
declared within an anonymous union. &#8212;<I>end note</I>]

</BLOCKQUOTE>

<P>Is a nested anonymous union a &#8220;non-static data member&#8221; or a
&#8220;nested type?&#8221; </P>

<P>See also issues <A HREF="57.html">57</A>,
<A HREF="1460.html">1460</A>, <A HREF="1562.html">1562</A>,
<A HREF="1587.html">1587</A>, <A HREF="1621.html">1621</A>,
and <A HREF="1623.html">1623</A>.</P>

<P><B>Proposed resolution (June, 2013):</B></P>

<P>Change 11.5 [<A href="https://wg21.link/class.union#5">class.union</A>] paragraph 5 as follows:</P>

<BLOCKQUOTE>

...The <I>member-specification</I> of an anonymous union shall only define
non-static data members. [<I>Note:</I> Nested types<INS>, anonymous
unions,</INS> and functions cannot be declared within an anonymous
union. &#8212;<I>end note</I>] The names of the members...

</BLOCKQUOTE>

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