[Issue 19097] Extend Return Scope Semantics

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 18 06:27:30 UTC 2018


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

Mike Franklin <slavo5150 at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slavo5150 at yahoo.com

--- Comment #2 from Mike Franklin <slavo5150 at yahoo.com> ---
Trying to dissect Walter's back-of-the-napkin description:

Example 1
---------
@safe:

int* frank(return scope int* p) { return p; }

void main()
{
    // lifetimes end in reverse order from which they are declared
    int* p;  // `p`'s lifetime is longer than `i`'s
    int i;   // `i`'s lifetime is longer than `q`'s
    int* q;  // `q`'s lifetime is the shortest

    q = frank(&i); // ok because `i`'s lifetime is longer than `q`'s
    p = frank(&i); // error because `i`'s lifetime is shorter than `p`'s
}

This works in the compiler today if both functions are declared @safe and if
compiled with -dip1000:  https://run.dlang.io/is/CZ3YuU

--


More information about the Digitalmars-d-bugs mailing list