Bug 11970 – Self-assigned variable expression with no effect doesn't have compiler error

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-22T08:23:44Z
Last change time
2018-04-26T05:01:54Z
Keywords
pull
Assigned to
No Owner
Creator
ilya-stromberg
See also
https://issues.dlang.org/show_bug.cgi?id=4791, https://issues.dlang.org/show_bug.cgi?id=17626

Comments

Comment #0 by ilya-stromberg-2009 — 2014-01-22T08:23:44Z
Reduced example: void main() { int i; i = i; } The code `i = i;` does nothing, but there are no compiler error. This error in real life: https://github.com/rejectedsoftware/vibe.d/issues/406 Note that we already have errors for no effect expression, for example for this code: `int i; i;` - `Error: var has no effect in expression (i)`.
Comment #1 by bearophile_hugs — 2014-01-22T09:53:04Z
Voted +1.
Comment #2 by slavo5150 — 2018-04-25T05:10:16Z
Comment #3 by slavo5150 — 2018-04-25T09:47:16Z
*** Issue 17626 has been marked as a duplicate of this issue. ***
Comment #4 by slavo5150 — 2018-04-26T01:26:32Z
Walter has ruled this unfixable and low impact: See comments in https://github.com/dlang/dmd/pull/8208 He suggests adding such checks to https://github.com/dlang-community/D-Scanner.