Bug 10578 – Postfix AA increment not considered side-effect

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-08T18:48:00Z
Last change time
2014-06-09T04:27:45Z
Keywords
rejects-valid
Assigned to
nobody
Creator
hsteoh

Comments

Comment #0 by hsteoh — 2013-07-08T18:48:28Z
CODE: ----SNIP---- import std.stdio; struct S { int x; ref S opUnary(string op)() if (op=="++") { x++; return this; } } void main() { S[int] aa; aa[0]++; // this is line 14 writeln(aa[0]); } ----SNIP---- DMD git HEAD (88b794d0) output: test.d(14): Error: var has no effect in expression (__pitmp1583) Changing aa[0]++ to ++aa[0] makes the problem go away. The error is wrong, since postfix ++ is a side-effect.
Comment #1 by yebblies — 2013-11-20T22:33:04Z
This happens because x++ is rewritten to (auto tmp = x, ++x, tmp)
Comment #2 by reachzach — 2013-11-20T23:19:47Z
*** Issue 7467 has been marked as a duplicate of this issue. ***
Comment #3 by k.hara.pg — 2014-06-09T04:27:45Z
*** This issue has been marked as a duplicate of issue 5810 ***