Bug 17245 – Errors about expressions with no effect only are given for basic types

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-03-07T15:11:33Z
Last change time
2024-12-13T18:51:48Z
Assigned to
No Owner
Creator
Jack Stouffer
Moved to GitHub: dmd#19239 →

Comments

Comment #0 by jack — 2017-03-07T15:11:33Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19239 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB