| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
April 14, 2015 Traits question and compiler crash | ||||
|---|---|---|---|---|
| ||||
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!
| ||||
April 14, 2015 Re: Traits question and compiler crash | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Filippo Fantini | 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/>. | |||
April 14, 2015 Re: Traits question and compiler crash | ||||
|---|---|---|---|---|
| ||||
Posted in reply to anonymous | 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/> | |||
April 14, 2015 Re: Traits question and compiler crash | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Filippo Fantini | correct link: https://issues.dlang.org/show_bug.cgi?id=14448 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply