<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2317</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="2317"></A><H4>2317.
  
Self-referential default member initializers
</H4>
<B>Section: </B>11.9.3&#160; [<A href="https://wg21.link/class.base.init">class.base.init</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD5
 &#160;&#160;&#160;

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2016-08-29<BR>


<P>[Accepted as a DR at the February, 2019 meeting.]</P>



<P>Consider an example like:</P>

<PRE>
  struct A {
    int n = A{}.n;
  };
</PRE>

<P>There doesn't seem to be a good reason to support this kind of thing,
and it would be simpler to say that a default member initializer can't
trigger any direct or indirect use of itself in general, rather than just
the two special cases that were banned by issues <A HREF="1696.html">1696</A> and <A HREF="1397.html">1397</A>.</P>

<P><B>Notes from the March, 2018 meeting:</B></P>

<P>There was a suggestion that creating an object of the containing
class in a default member initializer should be prohibited. That would
presumably be a difference between the reference member and non-reference
member cases, since the intent is to allow creation of a temporary for
a reference member to bind to. The suggested approach for drafting was
simply to remove the restriction to references in 9.5.2 [<A href="https://wg21.link/dcl.init.aggr#11">dcl.init.aggr</A>] paragraph 11.
</P>

<P><B>Proposed resolution (November, 2018):</B></P>

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

<BLOCKQUOTE>

If a <DEL>reference</DEL> member <DEL>is initialized from
its</DEL> <INS>has a</INS> default member initializer and a
potentially-evaluated subexpression thereof is an aggregate
initialization that would use that default member
initializer, the program is ill-formed.  [<I>Example:</I>

<PRE>
  struct A;
  extern A a;
  struct A {
    const A&amp; a1 { A{a,a} }; //<SPAN CLASS="cmnt"> OK</SPAN>
    const A&amp; a2 { A{} };    //<SPAN CLASS="cmnt"> error</SPAN>
  };
  A a{a,a};                 //<SPAN CLASS="cmnt"> OK</SPAN>

<INS>  struct B {
  int n = B{}.n;            //<SPAN CLASS="cmnt"> error</SPAN>
  };</INS>
</PRE>

<P>&#8212;<I>end example</I>]</P>

</BLOCKQUOTE>

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