www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - opApply and inout parameters

This code:

/////////////////////////////////
import std.stdio;

class A
{
    int opApply ( int delegate (inout char ) dg )
    {
        int r;
        foreach ( char c; "carlos" )
        {
            r = dg(c);
            if (r) break;
        }
        return r;
    }
}

void main()
{
    int a;
    foo(a);
    writefln(a);
}

void foo(inout int a)
{
    A aa = new A;
    foreach ( char c; aa )
        ++a;
    //++a;          //line 29
}

/////////////////////////////////

Outputs: 0. If A is a struct, it's the same.
Even worse: uncomment line 29 and you get an AV.
dmd 0.97, WinXP Pro and Win95.

-----------------------
Carlos Santander Bernal
Jul 29 2004