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.


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

the compiler just crashes instead.


These experiments were done with DMD v2.067.0 on Ubuntu x64 and on Windows x64.

Thank you!

Reply via email to