Traits question and compiler crash

Filippo Fantini via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 14 05:09:29 PDT 2015


On Tuesday, 14 April 2015 at 10:43:16 UTC, anonymous wrote:
> 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/>.


Thanks.
I've created an issue:
<https://issues.dlang.org/show_bug.cgi?id=14448/>


More information about the Digitalmars-d-learn mailing list