www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24385] New: Slicing a static array binds as non-ref when

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

          Issue ID: 24385
           Summary: Slicing a static array binds as non-ref when using
                    auto ref
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: schveiguy gmail.com

```d
import std.stdio;
void foo(ref int[2] val)
{
    writeln("foo ref");
}

void foo(int[2] val)
{
    writeln("foo non-ref");
}

void bar()(auto ref int[2] val)
{
    static if(__traits(isRef, val))
        writeln("bar ref");
    else
        writeln("bar non-ref");
}

void main()
{
    int[4] x;
    int[2] y;
    foo(y);         // foo ref
    bar(y);         // bar ref
    foo(x[0 .. 2]); // foo ref
    bar(x[0 .. 2]); // bar non-ref
}
```

They should all be ref for consistency.

--
Feb 10