This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


2317. Self-referential default member initializers

Section: 11.9.3  [class.base.init]     Status: CD5     Submitter: Richard Smith     Date: 2016-08-29

[Accepted as a DR at the February, 2019 meeting.]

Consider an example like:

  struct A {
    int n = A{}.n;

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 1696 and 1397.

Notes from the March, 2018 meeting:

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.4.2 [dcl.init.aggr] paragraph 11.

Proposed resolution (November, 2018):

Change 9.4.2 [dcl.init.aggr] paragraph 12 as follows:

If a reference member is initialized from its has a 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. [Example:
  struct A;
  extern A a;
  struct A {
    const A& a1 { A{a,a} }; // OK
    const A& a2 { A{} };    // error
  A a{a,a};                 // OK

  struct B {
  int n = B{}.n;            // error

end example]