On 05/12/2014 23:58, Walter Bright wrote:
2) `scope ref` return values cannot be stored.

     scope ref int foo();
     void bar(scope ref int a);

     foo().bar();        // allowed
     scope tmp = foo();  // not allowed
     tmp.bar();

Right

From the DIP:

"The lifetime of a scope return value is the lifetime of an rvalue. It may not be copied in a way that extends its life."

With part of the example:

scope int* foo();
...
int* p = foo();       // Error, lifetime(p) is ∞

Maybe the error should be 'scope return value cannot be stored', because otherwise p could be inferred as scope.

Reply via email to