[Issue 11307] Make const(T).init and immutable(T).init lvalues

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Apr 27 22:15:08 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=11307

--- Comment #3 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to monarchdodra from comment #0)
> ".init" is a global property, that is marked as rvalue, to prevent it being
> modified. This is correct behavior.
> 
> However, when "T" is const/immutable already, then it is illegal to modify
> it anyways. Making ".init" an lvalue for such cases has advantages.

Not only to prevent its modification, T.init makes an rvalue to prevent copy
construction on its usage.

  auto t = T.init;

If T.init returns an lvalue, initializing t will always invoke T's postblit if
exists.

--


More information about the Digitalmars-d-bugs mailing list