rvalue references

Diggory diggsey at googlemail.com
Sat Apr 27 16:38:53 PDT 2013


> I think 'scope' is yet to be fully defined. Returning a 
> reference doesn't necessarily mean escaping unsafely. The 
> primary goal is safety. From the perspective of the calling 
> function, something assigned 'scope' remains in scope even if 
> it's returned.

The keyword 'scope' is very well defined at the moment - it means 
among other things that the value cannot be returned. DIP25A 
depends on this being the case, changing it will break any hope 
of sensible semantics for safe references. I agree that rvalue 
references can be returned safely - that's my main point - so 
using "scope" to identify them makes no sense.

On Saturday, 27 April 2013 at 16:13:21 UTC, Zach the Mystic wrote:
> On Saturday, 27 April 2013 at 06:37:38 UTC, Manu wrote:
>> scope ref T func(scope ref T t) { return t; }
>>
>> I think this solves the problem.
>
> struct S {
>   scope ref S func() { return this; }
> }
>
> Does 'scope' apply to the return value or to the hidden 'this' 
> parameter? Or both? I think it makes a difference...

Unless the meaning of "scope" is dramatically changed it doesn't 
make sense for it to be applied to a return value, since scope 
values cannot be returned. Therefore it unambiguously refers to 
the hidden 'this' pointer.


More information about the Digitalmars-d mailing list