September 01, 2017 Easy bug: reference to local variable | ||||
---|---|---|---|---|
| ||||
Nothing new here but I almost fell prey to this bug today. Spot the bug: import std.stdio; import std.range; int[3] bar() { return [ 1, 2, 3 ]; } auto foo() { auto a = bar(); return zip(a[], a[]); } void main() { writeln(foo()); } In the real code, bar() was a call to std.datetime.benchmark, which also returns a static array. (The compiler is helpful in the trivial case of foo returning a[] instead of hiding it through zip.) DIP 1000 is targeting such bugs: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md Ali |
Copyright © 1999-2021 by the D Language Foundation