[Issue 21166] New: error message when unittesting std/array depends on -cov and -O switches
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Aug 16 04:36:57 UTC 2020
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 at puremagic.com
Reporter: schveiguy at 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.
--
More information about the Digitalmars-d-bugs
mailing list