Created on 2016-08-29.00:00:00 last changed 47 months ago
Proposed resolution (November, 2018):
Change 9.4.2 [dcl.init.aggr] paragraph 12 as follows:
If areferencememberis initialized from itshas 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]
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.
[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.
History | |||
---|---|---|---|
Date | User | Action | Args |
2020-12-15 00:00:00 | admin | set | messages: + msg6408 |
2020-12-15 00:00:00 | admin | set | status: drafting -> cd5 |
2018-04-11 00:00:00 | admin | set | messages: + msg6198 |
2018-04-11 00:00:00 | admin | set | status: open -> drafting |
2016-08-29 00:00:00 | admin | create |