Bug 5853 – Sorting SysTime: overlapping array copy

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-04-18T11:18:00Z
Last change time
2011-04-18T12:45:36Z
Assigned to
nobody
Creator
Jesse.K.Phillips+D

Comments

Comment #0 by Jesse.K.Phillips+D — 2011-04-18T11:18:17Z
Sorting std.datetime.SysTime with std.algorithm.sort results in: object.Exception@src\rt\arraycat.d(40): overlapping array copy import std.algorithm; import std.datetime; import std.array; void main() { auto arr = [ SysTime(DateTime(2011,4,4)), SysTime(DateTime(2011,3,22)) ]; auto ans = [ SysTime(DateTime(2011,3,22)), SysTime(DateTime(2011,4,4)) ]; assert(array(sort(arr)) == ans); }
Comment #1 by kennytm — 2011-04-18T12:23:38Z
I believe it is the same problem as issue 5705, except now the type to swap is a SysTime instead of a Tuple. ------------------------------------------------------------------ import std.algorithm; import std.datetime; import std.stdio; void main() { auto x = SysTime(DateTime(2011,4,4)); auto y = SysTime(DateTime(2011,4,4)); swap(x, y); writeln("ok"); swap(x, x); // <-- throws "overlapping array copy" writeln("ok"); } ------------------------------------------------------------------
Comment #2 by kennytm — 2011-04-18T12:45:36Z
OK it is definitely issue 5705. Making std.algorithm.swap do nothing when &lhs == &rhs in case of hasElaborateAssign let the problem go away. Marking as dupe. *** This issue has been marked as a duplicate of issue 5705 ***