[Issue 4277] delegate reference wrong scope var value

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 28 20:04:22 PDT 2010


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



--- Comment #6 from changlon <changlon at gmail.com> 2010-06-28 20:04:19 PDT ---
this is simpler testcase:
-----------------------------------------------------
version( D_Version2 ){
    mixin("extern(C) void printf(const(char)*, ... ) ;");
}else{
    extern(C) void printf(char*, ... );
}


class MyTest {
    void delegate(int)[]    list ;

    public void run(){
        test3(this);
        test2(this);
        test1(this);
        foreach( dg; list) {
            dg(3);
        }
    }

    static void test1(string name = "test1\0" )(MyTest obj){
        printf("out: `%s` = `%x` \n\0".ptr ,  name.ptr, cast(void*) obj );
        void     add(int i){
            printf("in: `%s` = `%x` \n\0".ptr ,  name.ptr, cast(void*) obj );
        }
            obj.list    ~= &add;
    }

    void test2(MyTest obj){
        test1!("test2\0")(obj);
    }

    void test3(ref MyTest obj){
        test1!("test3\0")(obj);
    }
}

void main(){
    auto t    = new MyTest;
    t.run;
}
---------------------------------------------------------------------------

my os is ubuntu 10.4 i386,

dmd1:
out: `test3` = `b750eff0`
out: `test2` = `b750eff0`
out: `test1` = `b750eff0`
in: `test3` = `8050844`
in: `test2` = `8050860`
in: `test1` = `bf89037c`


dmd2:
out: `test3` = `b7494fe0`
out: `test2` = `b7494fe0`
out: `test1` = `b7494fe0`
in: `test3` = `b7494fe0`
in: `test2` = `b7494fe0`
in: `test1` = `b7494fe0`

ldc:
out: `test3` = `b7549ff0`
out: `test2` = `b7549ff0`
out: `test1` = `b7549ff0`
in: `test3` = `3`
in: `test2` = `3`
in: `test1` = `bfaae088`

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