Thread overview
[Issue 15996] @safe allows escaping of ptrs to variables going out of scope
May 06, 2016
Eyal Lotem
May 06, 2016
Eyal Lotem
May 06, 2016
Sobirari Muhomori
Jun 07, 2016
Walter Bright
Aug 25, 2016
Walter Bright
Aug 27, 2016
Walter Bright
May 01, 2017
Nick Treleaven
May 06, 2016
https://issues.dlang.org/show_bug.cgi?id=15996

--- Comment #1 from Eyal Lotem <eyal.lotem@gmail.com> ---
Please ignore the attachment, it is a less simplified version of the reproduction.

--
May 06, 2016
https://issues.dlang.org/show_bug.cgi?id=15996

--- Comment #2 from Eyal Lotem <eyal.lotem@gmail.com> ---
Created attachment 1596
  --> https://issues.dlang.org/attachment.cgi?id=1596&action=edit
An even simpler reproduction of the bug

--
May 06, 2016
https://issues.dlang.org/show_bug.cgi?id=15996

Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, safe

--
June 07, 2016
https://issues.dlang.org/show_bug.cgi?id=15996

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
The attachment:
---------------------------

safe:

import std.stdio;

struct T { int y; }

auto foo() {
    auto t = T(12345);
    auto x = &t.y;
    return x;
}

unittest {
    auto x = foo();
    writeln("Hello world");
    assert(*x == 12345);
}

--
August 25, 2016
https://issues.dlang.org/show_bug.cgi?id=15996

--- Comment #4 from Walter Bright <bugzilla@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.

--
August 27, 2016
https://issues.dlang.org/show_bug.cgi?id=15996

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--
May 01, 2017
https://issues.dlang.org/show_bug.cgi?id=15996

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |nick@geany.org
         Resolution|---                         |FIXED

--- Comment #5 from Nick Treleaven <nick@geany.org> ---
Fixed as per comment 4, dmd 2.074 with -dip1000.

--