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

Iakh <iakt...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://forum.dlang.org/thre
                   |                            |ad/rdiwdveqfhevqugddwwd@for
                   |                            |um.dlang.org

--- Comment #3 from Iakh <iakt...@gmail.com> ---
(In reply to Steven Schveighoffer from comment #2)
Even this works:
import std.stdio;

int[] f(void[] a) @safe pure
{
    return cast(int[])a;
}

void main() @safe
{
    int[] a = new int[4];

    immutable b = a.f();
    writeln(b);
    a[0] = 1;
    writeln(b);
}

> One significant problem here is that the compiler may not consider the
> parameter to f in these cases to be a *return* avenue, only a parameter. The
> compiler should take into account references to ensure that they cannot
> escape the same data that is being returned.

So not only escape. Compiler just traverses params's AST and search for
exactly match with ReturnType.

> Fixing this may break a lot of code, but probably for the better. May need a
> deprecation cycle for this.

--

Reply via email to