[Issue 24385] New: Slicing a static array binds as non-ref when using auto ref
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Feb 10 16:49:35 UTC 2024
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 at puremagic.com
Reporter: schveiguy at 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.
--
More information about the Digitalmars-d-bugs
mailing list