https://issues.dlang.org/show_bug.cgi?id=22916

--- Comment #8 from Walter Bright <[email protected]> ---
(The cheat sheet was out of date. My bad. Remember when we changed `return
scope` to always mean ReturnScope, and `ref scope return` never means
`Ref-ReturnScope`?)

Let's change x to p for clarity:

  ref int f(ref return scope int* p) @safe
  { 
    return *p;
  }

This compiles as `ref` `return scope`. This protects the value of p. Not the
address of p. This compiles successfully, as the value of `p` is what is
returned.

Now let's try not having `return scope` next to each other:

  ref int f(ref5 scope return int* p) @safe
  { 
    return *p;
  }

This compiles as `return ref` `scope`. It fails to compile with:

    Error: scope variable `p` may not be returned.

Both are correct behavior. Note that `return scope` is *always* interpreted as
returnScope.

Also, the behavior is *always* determined by the function signature, not
whatever the return expression is.

--

Reply via email to