January 13, 2022 [Issue 22673] New: .array of a range with length preallocates without checking if the length was lying or not. | ||||
---|---|---|---|---|
| ||||
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? -- |
Copyright © 1999-2021 by the D Language Foundation