On Tuesday, 14 April 2015 at 09:24:04 UTC, Filippo Fantini wrote:
Hello everyone!

I'm new to D.
While playing with around with traits,
I ended up writing this short example:


module test;

class Foo
{
    private int _value = 21;

    void foo()
    {
        import std.traits;

alias funs = MemberFunctionsTuple!( typeof( this ), "bar" );

        version( crash )
        {
            void function( string ) b = &funs[ 0 ];
            b( "world" );
        }

        funs[ 0 ]( "world" );
    }

    void bar( string s )
    {
        import std.stdio;
        writeln( "hello ", s, "! ", _value );
    }
}

void main()
{
    auto f = new Foo();
    f.foo();
}


My first question is why building this with
dmd test.d

the line:
funs[ 0 ]( "world" );

does not crash, as I would expect because there's no this pointer to access _value when calling the member function.

That's the same as `Foo.bar("world");`, which also works. The this pointer is passed even though the call does not show it. I don't know if or where this is specified, but I'm pretty sure it's supposed to work like this.

The second question is why when building with:
dmd -version=crash test.d

the compiler just crashes instead.

Every compiler crash is a bug. Please report it at <http://issues.dlang.org/>.

Reply via email to