digitalmars.D.bugs - [Issue 7467] New: opUnary!"++" rejects valid, claiming "var has no effect in expression"
- d-bugmail puremagic.com (44/44) Feb 08 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7467
http://d.puremagic.com/issues/show_bug.cgi?id=7467 Summary: opUnary!"++" rejects valid, claiming "var has no effect in expression" Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: reachzach gmail.com --- Comment #0 from Zach the Mystic <reachzach gmail.com> 2012-02-08 15:40:51 PST --- 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 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 08 2012