www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22673] New: .array of a range with length preallocates


          Issue ID: 22673
           Summary: .array of a range with length preallocates without
                    checking if the length was lying or not.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: maxhaton gmail.com

struct Range
    enum size_t length = 100;
    enum size_t evilRealLength = 50;
    size_t idx;
    Type front()
        return Type(0);
    bool empty()
        return idx == evilRealLength;
    void popFront()
This will allocate 100 `Type`s but only 50 will be touched, what happens if
those later ones get destructed?

Jan 13 2022