Bug 3607 – Problems with struct opEquals and const

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-12-11T06:04:00Z
Last change time
2015-06-09T01:27:04Z
Assigned to
nobody
Creator
webby

Comments

Comment #0 by webby — 2009-12-11T06:04:18Z
While trying to build the Juno library with DMD 2.037, i got a bunch or errors like: juno\com\core.d(295): Error: function juno.com.core.GUID.opEquals type signature should be const bool(ref const(GUID)) not bool(GUID other) Which can be replicated with: //////////////////////////////// struct Foo { bool opEquals(Foo f) const { return true; } } void Bar() { Foo f; } //////////////////////////////// As mentioned in the post @ http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=18407, the error seems to have been caused by changeset 260, which was made to fix bug 3433.
Comment #1 by clugdbug — 2010-09-22T03:40:56Z
*** Issue 4289 has been marked as a duplicate of this issue. ***
Comment #2 by clugdbug — 2010-12-01T03:12:08Z
The error message is correct, and the code compiles if you change the signature to ref const Foo. The spec clearly states: "If structs declare an opEquals member function, it should follow the following form: struct S { int opEquals(ref const S s) { ... } }" A key point in the forum discussion, which was missing from the bug report was this comment: > I think it should be allowed to have a signature like this: > bool opEquals(T other) const > inside T as long as T can be implicitly cast from const to mutable. Changing to an enhancement request.
Comment #3 by webby — 2010-12-01T06:45:44Z
Shouldn't the spec say 'bool opEquals' instead of 'int opEquals' ?
Comment #4 by yebblies — 2011-06-12T22:44:02Z
*** This issue has been marked as a duplicate of issue 3659 ***