[Issue 15660] break "immutable" with pure function and mutable reference params

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Feb 9 09:48:25 PST 2016


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

Iakh <iaktakh at gmail.com> changed:

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

--- Comment #3 from Iakh <iaktakh at 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.

--


More information about the Digitalmars-d-bugs mailing list