www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - strange behavior with pointers to function with default args

<code>
import std.stdio;

void foo (int i, int j = 7){writef("foo(%d,%d)\n",i,j);}
void bar (int i, int j = 6){writef("bar(%d,%d)\n",i,j);}

void foo (int i){assert(0);}
void bar (int i){assert(0);}

void main(char[][] argv)
{
	{
	auto fp = &bar;
	fp(1);
	fp = & foo;
	fp(1);
	}

	{
	auto fp = &foo;
	fp(1);
	fp = & bar;
	fp(1);
	}
}
</code>

Prints:

bar(1,6)
foo(1,6)
foo(1,6)
bar(1,6)

Reversing the two blocks gives:

foo(1,7)
bar(1,7)
bar(1,7)
foo(1,7)

Placing the asserted functions first causes asserts. (Known issue: #52)

Is this correct??
Jun 13 2006