Return value storage classes - `scope` as well as `ref`

Dukc ajieskola at gmail.com
Tue May 30 07:43:07 UTC 2023


On Tuesday, 30 May 2023 at 07:21:44 UTC, Dukc wrote:
> No, this is working just as it should. `lf` is not `scope`, so 
> a return value of a `return scope` function should be neither.

Oh sorry, didn't read your whole post. You weren't claiming 
there's a bug but suggesting a new design. That is, making `lf` 
be `scope` with this syntax.

I still prefer the current solution, though. `scope` is an on/off 
attribute only from perspect of variables. Expression, though, 
have shortest possible lifetimes, meaning they figure out which 
local scope the result is guaranteed to last. `S(5)` is an 
expression, so the compiler needs to figure out it's shortest 
possible lifetime even if it isn't immediately assigned to a 
variable. What should it be? It isn't obvious.

What does work, without language changes, is giving a sentinel 
pointer parameter to the constructor that is used to figure out 
the shortest possible lifetime. That is, the constructor is 
defined `this(int, return scope void* sentinel)` and is used 
`S(5, &localVariableIWontOutlive)`.


More information about the Digitalmars-d mailing list