6672 – [CTFE] ICE on compile time std.algorithm.sort

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6672 - [CTFE] ICE on compile time std.algorithm.sort
Summary: [CTFE] ICE on compile time std.algorithm.sort
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
Reported: 2011年09月14日 23:35 UTC by timon.gehr
Modified: 2011年10月01日 14:15 UTC (History)
3 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2011年09月14日 23:35:53 UTC
import std.algorithm;
string foo(){
 auto kw=["alias", "align", "asm", "assert", "auto", "body", "bool", "break", "byte", "case", "cast", "catch", "cdouble", "cent", "cfloat", "char", "clas\
s", "const", "continue", "creal", "dchar", "debug", "default", "delegate", "delete", "deprecated"];
 sort(kw);
 return "success!";
}
pragma(msg, foo());
void main() {}
This fails with 
dmd: interpret.c:1845: virtual Expression* ArrayLiteralExp::interpret(InterState*, CtfeGoal): Assertion `((IndexExp*)e)->e1 != this' failed.
Comment 1 Don 2011年09月27日 00:15:37 UTC
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 bearophile_hugs 2011年09月30日 17:27:25 UTC
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 Don 2011年10月01日 00:02:48 UTC
(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;
}());


AltStyle によって変換されたページ (->オリジナル) /