[Issue 5363] New: const + alias this = wrong code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 21 19:32:55 PST 2010


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

           Summary: const + alias this = wrong code
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dsimcha at yahoo.com


--- Comment #0 from David Simcha <dsimcha at yahoo.com> 2010-12-21 19:30:58 PST ---
Happens on at least 2.050, 2.051.

import core.stdc.stdio;  // Pollutes asm less than std.stdio.

struct Foo {
    uint dummy = 0;
    uint k = 0;

    alias dummy this;  // Yes, this line is necessary for reproducing the bug.

    // This needs to be a function to reproduce the bug.  Setting k directly
    // doesn't cut it.
    void put(uint element) {
        k += element;
    }

    // rhs must be const to reproduce the bug.
    void put(const Foo rhs) {
        k += rhs.k;
    }
}

void main() {
    Foo foo1, foo2;
    foo1.put(10);
    foo2.put(42);
    foo1.put(foo2);

    printf("%d\n", foo1.k);  // 10, should be 52
}

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