Why can't I use an arbitrary nesting of braces to construct most classes?
There's a special case that precludes D{{}}
. It's a very particular set of conditions, so I imagine it's there specifically to prevent this exact recursion.
[over.best.ics]/4 However, if the target is
(4.1) — the first parameter of a constructor
...
and the constructor ... is a candidate by
...
(4.5) — the second phase of [over.match.list] when the initializer list has exactly one element that is itself an initializer list, and the target is the first parameter of a constructor of classX
, and the conversion is toX
or reference to cvX
,
user-defined conversion sequences are not considered.
D{{}}
is a list-initialization. D(D&&)
constructor is considered by the second phase of it (the first phase looks at initializer-list constructors, like C(std::initializer_list<C>)
in your second example). But for it to be viable, there needs to be an implicit conversion from {}
to D&&
, and [over.best.ics]/4 suppresses it.