Bug 11932 – alias this and sort produce wrong code

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-01-15T15:56:16Z
Last change time
2019-07-08T04:52:49Z
Assigned to
No Owner
Creator
Simon

Comments

Comment #0 by simon.buerger — 2014-01-15T15:56:16Z
When I use alias this to overload the comparison operators on a struct, sort gives wrong results on some inputs (dmd 2.64.2, 64bit Ubuntu). Minimal example to reproduce: struct S { int i; alias i this; } void main(string[] args) { auto arr = [S(1000),S(2000)]; arr[].sort; assert(arr[0] < arr[1]); }
Comment #1 by k.hara.pg — 2014-01-15T17:15:57Z
Built-in sort property cannot recognize alias this, because TypeInfo object does not have any information about alias this. That's one of the reason why it is planned to be deprecated.
Comment #2 by hsteoh — 2014-01-19T08:07:57Z
Workaround: use std.algorithm.sort instead of the built-in sort.
Comment #3 by monarchdodra — 2014-01-19T08:21:08Z
(In reply to comment #1) > That's one of the reason why it is planned to be deprecated. "Planned" ? What's the hold up? Can't we just straight up deprecate it? Or are there things that need to be done first?
Comment #4 by bearophile_hugs — 2014-01-19T10:58:15Z
(In reply to comment #3) > "Planned" ? What's the hold up? Can't we just straight up deprecate it? Or are > there things that need to be done first? I think there's nothing holding us back from deprecating the built-in sort. But there's something holding us back from deprecating the built-in reverse. But the two functions are separated and unrelated, to this shouldn't be a problem.
Comment #5 by hsteoh — 2014-01-19T17:40:23Z
I vote for deprecating the built-in sort in the next release.
Comment #6 by pro.mathias.lang — 2019-07-08T04:52:49Z
Built in sort is gone.