[Issue 16585] New: dmd thinks function returns unique result despite mutable indirection in parameter

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Oct 3 15:07:37 PDT 2016


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

          Issue ID: 16585
           Summary: dmd thinks function returns unique result despite
                    mutable indirection in parameter
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ag0aep6g at gmail.com

----
int[] fun(long[] arg) pure
{
    return cast(int[]) arg;
}
void main()
{ 
    long[] a = [1];
    immutable i = fun(a); /* Should be rejected. Only ok when fun(a) is
        actually unique. */
    immutable copy = i.dup;
    assert(copy == i); /* Passes. */
    a[0] = 2; /* Affects the immutable i. */
    assert(copy == i); /* Fails now. */
}
----

Possibly related to issue 15862.

--


More information about the Digitalmars-d-bugs mailing list