Bug 13902 – Compiler allows escaping the address of part of a local
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-12-27T23:36:00Z
Last change time
2015-02-18T03:42:19Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
andrei
Comments
Comment #0 by andrei — 2014-12-27T23:36:49Z
Currently the compiler disallows this:
ref int fun() {
int x;
return x; // escape the address of a local
}
However, this goes unchecked:
struct S {
int x;
}
ref int fun() {
S s;
return s.x; // escape the address of part of a local
}
Direct member access is easy to check using the same logic, so I'm filing this as a bug. DIP25 addresses more sophisticated detection cases.
Comment #1 by andrei — 2014-12-27T23:41:23Z
One more simple case, equivalent in fact because statically-sized arrays behave like structs:
ref int lun() {
int a[42];
return a[5];
}
This should also be disallowed directly.