Discussion Thread: DIP 1040--Copying, Moving, and Forwarding--Community Review Round 1

deadalnix deadalnix at gmail.com
Mon Mar 8 15:42:15 UTC 2021


On Monday, 8 March 2021 at 08:23:55 UTC, RazvanN wrote:
> "
> S func(return S s)
> {
>     S s2;
>     return s2;  // error, can't return local by Move Ref
> }
> "
>
> Isn't this rather restrictive?

It is important for soundness. When you pass by ref, the owner 
remains the caller, not the callee.

> I can imagine a scenario where you would like to return the 
> parameter if some condition is met or return a local otherwise:
>

Yes, absolutely, in which case you either want to return it by 
ref, or take it by value.



More information about the Digitalmars-d mailing list