[Issue 22040] New: dip1000: foreach ref can escape scope array
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 18 18:13:08 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22040
Issue ID: 22040
Summary: dip1000: foreach ref can escape scope array
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: safe, Vision
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
This is correctly rejected:
```
ref int f(ref scope int[] arr) {
foreach(ref e; arr)
return e; // Error: scope variable `__r2` may not be returned
assert(0);
}
```
This isn't: (`scope` => `return scope`)
```
ref int f(ref return scope int[] arr) {
foreach(ref e; arr)
return e;
assert(0);
}
```
The `return` applies to the `ref arr`, not the `int[]`. This is another case of
the compiler conflating `return ref` and `return scope` like in issue 21868.
--
More information about the Digitalmars-d-bugs
mailing list