Bug 19881 – Escaping reference to local through return scope with -dip1000 and @safe
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-05-16T22:10:47Z
Last change time
2019-05-19T03:35:54Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Simen Kjaeraas
Comments
Comment #0 by simen.kjaras — 2019-05-16T22:10:47Z
@safe int* fun(return scope int* input) {
int local = 123;
input = &local; // This line shouldn't compile
return input;
}
@safe void main() {
import std.stdio;
int* p;
p = fun(p);
(*p).writeln; // 123
(*p).writeln; // Random garbage
}
Comment #1 by maxhaton — 2019-05-16T23:46:53Z
I did a rough and ready check, and it doesn't look like this ever worked. i.e. no past build of dmd supporting dip1000 caught this
Comment #2 by dlang-bot — 2019-05-17T00:11:13Z
@lesderid created dlang/dmd pull request #9808 "Fix issue 19881 - escaping reference to local through return scope with -dip1000 and @safe" fixing this issue:
- Fix issue 19881 - escaping reference to local through return scope with -dip1000 and @safe
https://github.com/dlang/dmd/pull/9808
Comment #3 by dlang-bot — 2019-05-19T03:35:54Z
dlang/dmd pull request #9808 "Fix issue 19881 - escaping reference to local through return scope with -dip1000 and @safe" was merged into stable:
- c6ac85cf3c0fdef347dc36500defb20734ba5abb by Les De Ridder:
Fix issue 19881 - escaping reference to local through return scope with -dip1000 and @safe
https://github.com/dlang/dmd/pull/9808