Example
void main () {
Object a, b;
a == b;
}
gives no error.
The problem lies, as ketmar put it, with opEquals
> oops. no more error messages. yes, i know that this invokes
> `opEquals()`, and `opEquals()` can have side-effects. but what
> are the chances of writing such code *intentionally*?
Here, the compiler can be helpful by outputing an error if the used opEquals is marked as pure. There's no way that a pure opEquals should be used in an expression with no effect.
Comment #1 by jack — 2017-03-07T18:13:58Z
This should also apply to opCmp, and opBinaryRight
Comment #2 by dlang-bugzilla — 2017-07-01T18:38:38Z
(In reply to Jack Stouffer from comment #0)
> Here, the compiler can be helpful by outputing an error if the used opEquals
> is marked as pure. There's no way that a pure opEquals should be used in an
> expression with no effect.
A pure opEquals doesn't seem to generate a warning/error either:
struct S
{
bool opEquals(ref const S s) pure { return false; }
}
void fun()
{
S a, b;
a == b;
}
Comment #3 by robert.schadek — 2024-12-13T18:51:48Z