[Issue 20956] New: [DIP1000] @safe defeated by closure capturing ref parameter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 19 06:13:49 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20956
Issue ID: 20956
Summary: [DIP1000] @safe defeated by closure capturing ref
parameter
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: safe
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: pro.mathias.lang at gmail.com
```
import std.stdio;
struct Container { int[10] arr; }
void main () @safe
{
auto dg = getDg(42);
stompStack();
dg();
}
auto getDg (int val) @safe
{
Container c;
c.arr[] = val;
return forwardDg(c);
}
auto forwardDg (scope ref Container c) @safe
{
return () => writeln(c);
}
void stompStack () @safe
{
int[256] oops = int.max;
}
```
This should print:
```
Container([42, 42, 42, 42, 42, 42, 42, 42, 42, 42])
```
Instead it prints:
```
Container([2147483647, 2147483647, 2147483647, 2147483647, 2147483647,
2147483647, 2147483647, 2147483647, 2147483647, 2147483647])
```
Compiled with `-preview=dip1000`. I would have tried `-preview=dip1021` if it
didn't SEGV the compiler.
```
% dmd | head -n 1
DMD64 D Compiler v2.092.1
```
--
More information about the Digitalmars-d-bugs
mailing list