[Issue 8916] New: How about to disable ++, --, and assignments to non-lvalues?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 30 08:47:16 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8916

           Summary: How about to disable ++, --, and assignments to
                    non-lvalues?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2012-10-30 18:47:15 MSK ---
Disabling ++, -- and assignments to non-lvalues (opAssign, opOpAssign,
opIndexAssign, opIndexOpAssign, opSliceAssign, opSliceOpAssign) will allow to
define user types with same semantics as build-in types (arithmetic and static
arrays):

---
struct S
{
    void opUnary(string op : "++")() { }
    void opAssign(int) { }
}

int iFunc() { return 0;   }
int[1] sarrFunc() { return [0];   }
S   sFunc() { return S(); }

void main()
{
    ++int.init;  // Error: constant 0 is not an lvalue
    ++iFunc();   // Error: iFunc() is not an lvalue

    ++(int[1]).init;  // Error: [0] is not an lvalue
    ++sarrFunc();     // Error: sarrFunc() is not an lvalue

    // currently compiles, but shouldn't:
    ++S.init;
    ++sFunc();

    S.init = 3;
    sFunc() = 3;
}
---

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


More information about the Digitalmars-d-bugs mailing list