digitalmars.D.bugs - [Issue 21166] New: error message when unittesting std/array depends
- d-bugmail puremagic.com (54/54) Aug 15 2020 https://issues.dlang.org/show_bug.cgi?id=21166
https://issues.dlang.org/show_bug.cgi?id=21166 Issue ID: 21166 Summary: error message when unittesting std/array depends on -cov and -O switches Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: schveiguy yahoo.com If you clone the current phobos master, and run the unittest specifically for std/array by doing: make -f posix.mak std/array.test you will get the error: Error: variable theArray used before set For the return statement in the following code in std.array: auto ret = (() trusted { Unqual!U[n] theArray = void; return theArray; }()); I reduced this using dustmite and hand editing down to the following code: auto staticArray(size_t U, R)(R input) { import std.range; alias ElementType!R T; auto res = () trusted { T[U] theArray = void; return theArray; }(); foreach(i, x; input) res[i] = x; return res; } safe void main() { auto input = [0, 1]; auto arr = input.staticArray!2; assert(arr[] == input); } This code fails with: dmd -O -cov file.d If you remove either of those options, it compiles and runs. If you change the static array line from input.staticArray!2 to input.staticArray!3 (and change the input size accordingly), it compiles and runs. I tested all the way back to 2.060 on run.dlang.io, and it fails for every version. --
Aug 15 2020