[Issue 21748] New: Return value of forward-referenced auto ref function mistakenly treated as lvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Mar 22 22:32:44 UTC 2021


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

          Issue ID: 21748
           Summary: Return value of forward-referenced auto ref function
                    mistakenly treated as lvalue
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.096.0, the following program compiles and runs without error:

---
void main()
{
    fun() = 1;
}

auto ref int fun()
{
    return 42;
}
---

However, if the order of the functions is swapped:

---
auto ref int fun()
{
    return 42;
}

void main()
{
    fun() = 1;
}
---

...then the compiler correctly issues the following error:

---
bug.d(8): Error: `fun()` is not an lvalue and cannot be modified
---
​

--


More information about the Digitalmars-d-bugs mailing list