digitalmars.D.bugs - [Issue 22673] New: .array of a range with length preallocates
- d-bugmail puremagic.com (37/37) Jan 13 2022 https://issues.dlang.org/show_bug.cgi?id=22673
https://issues.dlang.org/show_bug.cgi?id=22673 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() { ++idx; } } ``` This will allocate 100 `Type`s but only 50 will be touched, what happens if those later ones get destructed? --
Jan 13 2022