Bug 14238 – DIP25: escape checks can be circumvented with delegate
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-02T20:59:00Z
Last change time
2017-01-16T23:26:40Z
Keywords
accepts-invalid, pull, safe
Assigned to
nobody
Creator
schuetzm
Comments
Comment #0 by schuetzm — 2015-03-02T20:59:11Z
The following code compiles with the -dip25 switch:
alias Fn = ref int delegate();
ref int foo(scope Fn fn) {
return fn();
}
ref int bar() {
int x;
ref int baz() {
return x;
}
return foo(&baz);
}
void main(string[] args) {
import std.stdio;
int x;
writefln("&x = %s", &x);
int* p = &bar();
writefln("p = %s", p);
}
Output:
&x = 7FFFF64F0728
p = 7FFFF64F0708
As can be seen, `p` points to a location further down the stack.
Comment #1 by bugzilla — 2016-06-30T05:39:37Z
The problem here is that 'scope' is not implemented.