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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Feb 9 08:35:43 PST 2016


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

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
                 CC|                            |schveiguy at yahoo.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #2 from Steven Schveighoffer <schveiguy at yahoo.com> ---
This doesn't require member functions.

int[] f(ref void[] m) pure
{
    auto result = new int[5];
    m = result;
    return result;
}

void main()
{
    void[] v;
    immutable x = f(v);
}

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.

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