[DIP] In-place struct initialization
Chris Wright via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 5 06:44:59 PDT 2016
On Fri, 05 Aug 2016 06:12:24 +0000, ZombineDev wrote:
> I was actually looking for design issues. Assuming this bug gets fixed,
> and S s = { a: var1, b: var2 }, becomes equivalent to:
> S s = void;
> s.a = var1; /* calls s.a postblit if necessary */
> s.b = var2; /* calls s.b postblit if necessary */
>
> Are there any *design* problems that I did not foresee, that make my
> proposal not worthwhile pursuing?
Your proposal is convenient because it's easily lowerable. It seems fine
as initialization where the LHS must be a variable declaration.
It would add a new edge case if the LHS could be some other expression.
Specifically, s.a.postblit could get a reference to s before it's fully
initialized, even though assignment looks atomic. You could resolve that
by copying everything first and running postblits after.
More information about the Digitalmars-d
mailing list