[Issue 23096] New: return auto ref does wrongly inferred with member function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 6 12:08:46 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23096
Issue ID: 23096
Summary: return auto ref does wrongly inferred with member
function
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: jlourenco5691 at gmail.com
The member function returns a ref instead of an lvalue.
```
struct Foo
{
auto ref get() { return i; }
int i;
}
auto ref get()(auto ref Foo foo) { return foo.i; }
void main()
{
static assert(!__traits(compiles, &get(Foo(4)))); // ok
static assert(!__traits(compiles, &Foo(4).get())); // fails
}
```
This probably happens because this bit of code does not fail also
```
struct Foo
{
ref get() { return i; }
int i;
}
void main()
{
auto p = &Foo(4).get;
}
```
--
More information about the Digitalmars-d-bugs
mailing list