[Issue 17364] New: Difference between slicing a slice and a reference to a slice

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon May 1 11:47:28 PDT 2017


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

          Issue ID: 17364
           Summary: Difference between slicing a slice and a reference to
                    a slice
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: kinke at gmx.net

DMD treats these 2 cases differently, while GDC works as expected and LDC is
being fixed accordingly:

```
@safe:

int[] globalArray;

ref int[] getSliceRef() { return globalArray; }

int getLowerBound()
{
    globalArray = [ 666 ];
    return 0;
}

void main()
{
    globalArray = [ 1 ];
    auto r1 = globalArray[getLowerBound() .. $];
    assert(r1 == [ 666 ]);

    globalArray = [ 1 ];
    auto r2 = getSliceRef()[getLowerBound() .. $];
    assert(r2 == [ 1 ]); // BUG, should be [ 666 ]
}
```

--


More information about the Digitalmars-d-bugs mailing list