www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7467] New: opUnary!"++" rejects valid, claiming "var has no effect in expression"


           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 == "++" ) {

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
(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,

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 08 2012