digitalmars.D.learn - Easy bug: reference to local variable
- =?UTF-8?Q?Ali_=c3=87ehreli?= (19/19) Sep 01 2017 Nothing new here but I almost fell prey to this bug today. Spot the bug:
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
Sep 01 2017