Reduced test case. Interestingly, the fact that this crashes shows that in the quicksort range, std.sort sometimes swaps elements with themselves! Sounds inefficient, is that behaviour correct?
void bug6672(ref string lhs, ref string rhs)
{
auto tmp = lhs;
lhs = rhs;
rhs = tmp;
}
static assert( {
auto kw = ["a"];
bug6672(kw[0], kw[0]);
return true;
}());
Comment #3 by bearophile_hugs — 2011-09-30T17:27:25Z
Now the code gives a different error (this error is not produced if this sorting is done at run time):
...\dmd2\src\phobos\std\algorithm.d(6662): Error: "Failed to sort range of type string[]. Actual result is: [alias, align, asm, assert, auto, body, bool, break]..."
test5.d(8): called from here: sort(kw)
test5.d(12): called from here: foo()
foo()
Comment #4 by clugdbug — 2011-10-01T00:02:48Z
(In reply to comment #3)
> Now the code gives a different error (this error is not produced if this
> sorting is done at run time):
>
> ...\dmd2\src\phobos\std\algorithm.d(6662): Error: "Failed to sort range of type
> string[]. Actual result is: [alias, align, asm, assert, auto, body, bool,
> break]..."
> test5.d(8): called from here: sort(kw)
> test5.d(12): called from here: foo()
> foo()
Aargh, I really fouled that up! Not fixed.
Here's a reduced test case.
void bug6672b(ref string lhs)
{
string tmp = lhs;
lhs = "b";
assert(tmp == "a");
}
static assert( {
string q = "m";
bug6672b(q);
return true;
}());
Comment #5 by bearophile_hugs — 2011-10-01T13:56:47Z