D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6948 - Possible bug in compiler or documentation regarding signature of opCmp()
Summary: Possible bug in compiler or documentation regarding signature of opCmp()
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2011-11-14 13:07 UTC by kukac
Modified: 2012-01-21 01:02 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kukac 2011-11-14 13:07:07 UTC
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 Alex Rønne Petersen 2011-11-14 13:20:44 UTC
It is by design that only that specific overload works (see The D Programming Language). The documentation is wrong here.