Bug 6948 – Possible bug in compiler or documentation regarding signature of opCmp()

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-11-14T13:07:00Z
Last change time
2012-01-21T01:02:40Z
Keywords
spec
Assigned to
nobody
Creator
kukac

Comments

Comment #0 by kukac — 2011-11-14T13:07:07Z
The documentation http://www.digitalmars.com/d/2.0/arrays.html writes that "For the .sort property to work on arrays of structs or unions, the struct or union definition must define the function: int opCmp(S) or int opCmp(S*)". That is misleading, as, in my experience, a struct must implement exactly "int opCmp(ref const S) const" in order to get .sort work. Signatures which are a bit different do not work. The documentation should be updated as soon as possible, either informing the programmer about a current bug in the compiler, or clearly stating that only this signature works! In addition, I think that the compiler should warn about using a likely incorrect signature.
Comment #1 by alex — 2011-11-14T13:20:44Z
It is by design that only that specific overload works (see The D Programming Language). The documentation is wrong here.
Comment #2 by bugzilla — 2012-01-21T01:02:40Z