Bug 7467 – opUnary!"++" rejects valid, claiming "var has no effect in expression"
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-08T15:40:00Z
Last change time
2013-11-20T23:19:47Z
Keywords
rejects-valid
Assigned to
nobody
Creator
reachzach
Comments
Comment #0 by reachzach — 2012-02-08T15:40:51Z
struct Arc {
int I = 0;
// This is void, but the error appears under all return types
void opUnary(string op)() if( op == "++" ) {
++I;
}
}
struct HasArc {
Arc myArc;
}
void main() {
import std.stdio;
HasArc has;
writefln(" Arc.I = %s", has.myArc.I); // Arc.I = 0
has.myArc++; // Error: var has no effect in expression (__pitmp1481)
// Okay, try this instead:
auto UselessVar = has.myArc++; // Works fine
writefln(" Arc.I = %s", has.myArc.I); // Arc.I = 1
}
Obviously the expression has an effect. I was informed by Timon Gehr that
"This is indeed a bug. The expression is rewritten internally into (pseudo code)
(auto __pitmp1481 = has.myArc, has.myArc.opUnary!"++"(), __pitmp1481);
It turns out the work around is so easy, "++has.myArc;".
Hopefully the bug fix won't be much harder!
Thank you,
Zach
Comment #1 by reachzach — 2013-11-20T23:19:47Z
*** This issue has been marked as a duplicate of issue 10578 ***