dip1000 return scope dmd v 2.100
vit
vit at vit.vit
Fri May 6 09:24:06 UTC 2022
Hello, new dmd (2.100) has return/scope changes.
It look like examples at page
https://dlang.org/spec/function.html#ref-return-scope-parameters
are no longer relevant.
What difference are between `return scope`, `scope return` and
`return`?
Why `void* ptr` in struct change effect of `scope return` ?
```d
@safe:
struct A{
int val;
//void* ptr;
int* test() scope return{
return &this.val; // OK
}
}
struct B{
int val;
void* ptr;
int* test() return{
return &this.val; // OK
}
}
struct C{
int val;
void* ptr;
int* test() scope return{
return &this.val; // Error: returning `&this.val` escapes a
reference to parameter `this`
}
}
void main(){}
```
More information about the Digitalmars-d-learn
mailing list