www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7733] New: [tdpl] opIndexUnary not called with postfix increment/decrement operators

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7733

           Summary: [tdpl] opIndexUnary not called with postfix
                    increment/decrement operators
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx


--- Comment #0 from hsteoh quickfur.ath.cx 2012-03-19 10:56:39 PDT ---
struct S {
    int[] data;
    void opIndex(size_t i) { return data[i]; }
    void opIndexUnary(string op)(size_t i) {
        return mixin(op ~ "data[i]");
    }
}
void main() {
    S s;
    s.data = [1,2,3];
    ++s[0]; // OK
    s[0]++; // Error: s.opIndex(1u) is not an lvalue
}

This contradicts the specs, that specify that x++ is translated to ++x, which
should cause opIndexUnary!"++" to be called, not opIndex.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 19 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7733



--- Comment #1 from hsteoh quickfur.ath.cx 2012-03-19 10:57:58 PDT ---
Oops, typo in previous post: should be int opIndex(size_t i), not void.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7733



--- Comment #2 from hsteoh quickfur.ath.cx 2012-03-20 06:50:03 PDT ---
TDPL references:

p.378: "Postincrement and postdecrement are generated automatically from
preincrement and predecrement, as described in  12.2.2 on page 369.

p.369: describes the rewriting of x++ as ++x when the value is not needed, and
as ((ref x){auto t=x; ++x; return t;})(a) when the value is needed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 20 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7733


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |monarchdodra gmail.com
         Resolution|                            |DUPLICATE


--- Comment #3 from monarchdodra gmail.com 2012-07-26 01:28:53 PDT ---
*** This issue has been marked as a duplicate of issue 5044 ***

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