Le 18/05/2012 22:35, Andrei Alexandrescu a écrit :
On 5/18/12 1:59 PM, Steven Schveighoffer wrote:
On Fri, 18 May 2012 14:30:46 -0400, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> wrote:

On 5/18/12 1:22 PM, Mehrdad wrote:
My brain just exploded.
Can someone explain what's going on?

class Test
{
public void foo() { }
}

static assert(is(typeof(&Test.foo) == void function()));

Looks like a bug. The assert should pass only if foo were static.

No, this is not a bug.

It is.

The purpose is so you can get the function pointer portion of a delegate
without an instance of the object.

Typing is what it is. The following program is unsound without a cast in
sight:

class Test
{
void foo() { writeln("foo"); }
}

static assert(is(typeof(&Test.foo) == void function()));

void fun()
{
writeln("fun");
}

void main() {
alias void function() TFun;
TFun a = &fun;
a();
a = &Test.foo;
a();
}

At best things could be arranged that &Test.foo has type void
function(Test) or something.


Andrei

It would be nice, but require a way to express that calling convention (thiscall is often different than simply passing an argument).

I proposed extern(this).

This would have the extra benefice of being able to declare UFCS with thiscall convention.

If the extern isn't added, the feature must go, it is made to write bugs.

Reply via email to