Discussion: Rvalue refs and a Move construtor for D

kinke kinke at gmx.net
Thu Sep 5 15:05:12 UTC 2019


On Thursday, 5 September 2019 at 13:03:04 UTC, Les De Ridder 
wrote:
> On Thursday, 5 September 2019 at 12:09:33 UTC, Eduard Staniloiu 
> wrote:
>> I would expect the contents of the moved lvalue to be reset to 
>> `Foo.init`.
>
> I believe that's what kinke is proposing too?

Yes, in my latest post, after destructing the moved-from lvalue 
right after the call (primarily to allow for a 2nd destruction).

I haven't gotten round to think a lot about corner cases, but the 
intention is to make high-level by-value passing as efficient as 
possible, without ugly rvalue ref complications, and not to 
bother the language user about what's going on under the hood.

One corner case would be:

T callee(T param) { return param; }
lval = callee(move(lval));

`lval` in memory would both be input and output at the same time, 
firstly leading to an invalid memcpy, and secondly, it would be 
destructed and reset to T.init after the call. This restriction 
could be described as rule 'do not access the lvalue to be moved 
anywhere else in the statement'.


More information about the Digitalmars-d mailing list