[Issue 15996] New: @safe allows escaping of ptrs to variables going out of scope
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri May 6 00:52:54 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15996
Issue ID: 15996
Summary: @safe allows escaping of ptrs to variables going out
of scope
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: eyal.lotem at gmail.com
Created attachment 1595
--> https://issues.dlang.org/attachment.cgi?id=1595&action=edit
Reproduces the undefined behavior
This code compiles and produces Undefined Behavior:
@safe:
import std.stdio;
struct T { int y; }
auto foo() {
int *x;
T t;
t.y = 12345;
x = &t.y;
return x;
}
unittest {
auto x = foo();
writeln("Hello world");
assert(*x == 12345);
}
It seems that the escape analysis checks if the pointed element is itself
directly declared on the stack, instead of checking whether it is contained in
something that is declared on the stack.
--
More information about the Digitalmars-d-bugs
mailing list