Bug 5773 – sort() and topN() fail on sliced/resized array of tuples

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-03-23T12:52:00Z
Last change time
2013-01-07T23:38:59Z
Assigned to
andrei
Creator
magnus

Comments

Comment #0 by magnus — 2011-03-23T12:52:03Z
Sample program: import std.algorithm, std.typecons; void main() { alias Tuple!(real,uint) entry; auto entries = new entry[100]; foreach (i, ref e; entries) { e[0] = 3.14*i; e[1] = i; } entries = entries[1 .. $]; // sort(entries); // topN(entries, 50); } When uncommented (on their own), the sort statement gives a segmentation fault, and the topN statement gives the error "object.Exception@src/rt/arraycat.d(40): overlapping array copy".
Comment #1 by magnus — 2011-03-23T13:17:29Z
Perhaps this is just me being stupid -- trying to sort things that can't be compared? However, if I use a custom struct (instead of a tuple) I get an explicit compiler error about that (which is kind of useful ;-)
Comment #2 by andrei — 2011-03-23T15:19:12Z
Thanks for the findings. They definitely point to bugs in sort and topN.
Comment #3 by kennytm — 2011-03-23T16:00:52Z
(In reply to comment #1) > Perhaps this is just me being stupid -- trying to sort things that can't be > compared? However, if I use a custom struct (instead of a tuple) I get an > explicit compiler error about that (which is kind of useful ;-) Except that Tuples *can* can compared. Example: ---------- import std.typecons; alias Tuple!(real,uint) Entry; void main(){ assert(Entry(1.0, 4) > Entry(0.5, 9)); } -----------
Comment #4 by kennytm — 2011-03-23T16:13:23Z
The overlapping array copy exception should be the same as issue 5705. Not sure about the segfault, as I can't reproduce a segfault (only the same overlapping array copy exception is thrown).
Comment #5 by lovelydear — 2012-04-23T02:23:47Z
Compiles and runs on 2.059 Win32.
Comment #6 by andrei — 2013-01-07T23:38:59Z
Fixed as far back as 2.059.