[Issue 15996] @safe allows escaping of ptrs to variables going out of scope

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 25 00:14:31 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15996

--- Comment #4 from Walter Bright <bugzilla at digitalmars.com> ---
(In reply to Walter Bright from comment #3)
> The attachment:
> ---------------------------
> 
> safe:
> 
> import std.stdio;
> 
> struct T { int y; }
> 
> auto foo() {
>     auto t = T(12345);
>     auto x = &t.y;
>     return x;              // line 10
> }
> 
> unittest {
>     auto x = foo();
>     writeln("Hello world");
>     assert(*x == 12345);
> }

With:

    https://github.com/dlang/dmd/pull/5972

now yields:

    test3.d(10): Error: scope variable x may not be returned

so this is resolved once 5972 is pulled.

--


More information about the Digitalmars-d-bugs mailing list