[Issue 23739] New: Can't return by ref from opApply iteration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 25 00:44:00 UTC 2023


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

          Issue ID: 23739
           Summary: Can't return by ref from opApply iteration
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: timon.gehr at gmx.ch

DMD 2.102.1:

---
struct S{
    int x;
    int opApply(scope int delegate(ref int x) dg){
        return dg(x);
    }
}

ref int foo(ref S s){
    foreach(x;s)
        return x;
    assert(0);
}

void main(){
    auto s=new S;
    assert(&foo(*s) is &s.x); // fail
}
---

The assertion should pass.

--


More information about the Digitalmars-d-bugs mailing list