[Issue 5044] New: opIndexUnary not working for post++

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 11 17:44:41 PDT 2010


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

           Summary: opIndexUnary not working for post++
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: ah08010-d at yahoo.com


--- Comment #0 from Austin Hastings <ah08010-d at yahoo.com> 2010-10-11 17:44:11 PDT ---
This code:
==========
module scratch;

class C( element_t ) {

    element_t [] contents;

    element_t opIndex( int index ) {
        return contents[ index ];
    }

    element_t opIndexUnary( string op )( int index ) {

        static if( op == "++" ) {
            return ++contents[ index ];
        }
        else {
            static assert( false );
        }
    }

}

unittest {
    auto c = new C!int();

    c[0]++;
}
==========
Produces this output:
==========
$ dmd -c -unittest scratch.d
scratch.d(42): Error: c.opIndex(0) is not an lvalue
==========
But if the penultimate line: "c[0]++" is replaced by "++c[0]", there is no
problem.

And finally, if the opIndex is changed to return a 'ref', there is not problem,
but the opIndexUnary operator is not called - the reference is incremented as
an int, I think.

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