DIP69 - Implement scope for escape proof references

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Dec 4 07:25:34 PST 2014


int* bar(scope int*);
scope int* foo();

bar(foo());           // Ok, lifetime(foo()) > lifetime(bar())

I'm trying to understand how foo can be implemented in any case. It has 
no scope ints to return, so where does it get the int from?

I don't see where the proposal defines what exactly can be returned via 
scope.

Another thing I saw early on:

void abc() {
     scope int* a;
     int* b;
     scope ref int* c = a;  // Error, rule 5
     scope ref int* d = b;  // Ok
     int* i = a;            // Ok, scope is inferred for i
     global_ptr = d;        // Error, lifetime(d) < lifetime(global_ptr)
     global_ptr = i;        // Error, lifetime(i) < lifetime(global_ptr)
     int* j;                // Ok, scope is inferred for i
     global_ptr = j;        // Ok, j is not scope
}

Does this mean ref can now be applied to a variable?

I'm not sure what the difference between scope ref and scope is. is d 
defined as a reference to b, or is d defined as a new variable that is 
initialized to what b points at (a la C++ &) ?

-Steve


More information about the Digitalmars-d mailing list