www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22092] New: [REG2.067] for loop over range with closure loops


          Issue ID: 22092
           Summary: [REG2.067] for loop over range with closure loops
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

///////////////////// test.d /////////////////////
void formatRange(T)(T val)
    for (size_t i; !val.empty; val.popFront, i) {}

void fun() {}

auto makeRange()()
    int pos;
    struct R
        bool empty() { return pos == 3; }
        void popFront() const

            version (no_bug) fun();
    return R();

void main()
    auto r = makeRange;

Note that with -version=no_bug (i.e. adding a call to an empty function), the
bug does not manifest.

Introduced in https://github.com/dlang/dmd/pull/3956

Jun 29 2021