www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15351] New: foreach by ref accepted, although front returns

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

          Issue ID: 15351
           Summary: foreach by ref accepted, although front returns by
                    value
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: schuetzm gmx.net

This compiles, but IMO shouldn't, because S.front doesn't return by ref:

struct S {
     property int front() { return 0; }
     property bool empty() { return false; }
    void popFront() { }
}

void main() {
    foreach(ref i; S()) { }
}

--
Nov 17 2015