Easy bug: reference to local variable
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Sep 1 14:00:05 PDT 2017
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
More information about the Digitalmars-d-learn
mailing list