3 ms·
That's cool, though it doesn't seem to work through a level of indirection. https://d.godbolt.org/z/zkm39N https://d.godbolt.org/z/zkm39N (I don't know much ab
by Arnavion 8y ago
That's cool, though it doesn't seem to work through a level of indirection. https://d.godbolt.org/z/zkm39N https://d.godbolt.org/z/zkm39N
(I don't know much about dlang. I got the compiler flags from googling and happening upon the test case in this PR https://github.com/dlang/dmd/pull/8504/files#diff-bb6a3ed8a54c32937449b30e34a2380c https://github.com/dlang/dmd/pull/8504/files#diff-bb6a3ed8a5... )
- WalterBright 8y agoThe code has to be annotated with `@safe:` and use the `-dip1000` compiler flag, which enables the checking. With such: test.d(9): Error: reference to local variable s assigned to non-scope s.i
- Arnavion 8y agoThanks. Indeed it needs the attribute like `@safe: S* foo() {` (and `-dip1000` seems to be unnecessary with it).
- Arnavion 8y agoTo correct my comment: `-dip1000` is still needed because `@safe` is overly restrictive. `@safe` prevents taking the address of `s` entirely regardless of how it's used, so `-dip1000` is needed to allow it when it's safe (such as using `&s` without letting it escape scope).