D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7706 - Comparing struct rvalues
Summary: Comparing struct rvalues
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2012-03-13 21:17 UTC by Kasumi Hanazuki
Modified: 2024-12-13 17:59 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kasumi Hanazuki 2012-03-13 21:17:28 UTC
The spec says in operatoroverloading.dd:

| Comparison operations are rewritten as follows:
|   ``a < b'' to ``a.opCmp(b) < 0'' or ``b.opCmp(a) > 0''

and

| If structs declare an opCmp member function, it should follow the following form:
|
| struct S {
|   int opCmp(ref const S s) const { ... }
| }

If you follow these specs, you cannot accept comparison between two rvalues.
For example S(0) < S(1), which is rewritten as S(0).opCmp(S(1)), is rejected _correctly_ by current DMD implementation (2.059HEAD).


In order to resolve this problem, comparison operators on struct types must be translated as follows:
  a < b
  to  (const _tmpb = b), a.opCmp(_tmpb) < 0
  or  (const _tmpa = a), b.opCmp(_tmpa) > 0
Comment 1 Kasumi Hanazuki 2012-03-13 21:21:44 UTC
Forgot to mention there is the same problem with opEquals and ==/!=.
Comment 2 Kasumi Hanazuki 2012-03-13 23:29:50 UTC
ah, my idea improves nothing than allowing rvalue-to-const-ref conversion. forget about it.
Comment 3 dlangBugzillaToGithub 2024-12-13 17:59:12 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18427

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB