void g(scope void delegate(scope int*) @safe cb) @safe {
int x = 42;
cb(&x);
}
void main() @safe {
int* p;
void f(scope int* i) @safe {
p = i;
}
g(&f);//在过期栈帧中取局部变量指针.
// x地址逃出了g.
assert(*p == 42);
}
因为,考虑参数
生命期比局部变量
生命期长.而不考虑参数/局部变量
是否属于同一函数.