Thread overview
possible bug with function pointers and aliases
May 15, 2006
BCS
May 16, 2006
Derek Parnell
May 16, 2006
BCS
May 15, 2006
Is this proper operation?

-------------
void fn(){assert(0);}	// make a function

void gm(){assert(0);}	// make another function

alias gm fn;		// alias the second with the name of the first

void main()
{			// make pointer-to-function from name
	void function() fnp = & fn;
			// call pointer-to-function
	fnp();

	// fn();	// wont compile with this line included
}
-------------

This compiles and calls the first function. However if the function "fn" is called directly, a compile time error is generated.

This seems to be another manifestation of DMD's failure to check for multiple choices when filling a pointer type.

(see: http://d.puremagic.com/bugzilla/show_bug.cgi?id=52)
May 16, 2006
On Mon, 15 May 2006 15:22:59 -0700, BCS wrote:

> Is this proper operation?
> 
> -------------
> void fn(){assert(0);}	// make a function
> 
> void gm(){assert(0);}	// make another function
> 
> alias gm fn;		// alias the second with the name of the first
> 
> void main()
> {			// make pointer-to-function from name
> 	void function() fnp = & fn;
> 			// call pointer-to-function
> 	fnp();
> 
> 	// fn();	// wont compile with this line included
> }
> -------------
> 
> This compiles and calls the first function. However if the function "fn" is called directly, a compile time error is generated.

I think it should be a compile error. However the error that is shown is really weird!

  test.d(13): function test.fn called with argument types:
          ()
  matches both:
          test.fn()
  and:
          test.gm()

I think is should fail at compile time because you are trying to have two identical identifier names in the same scope, namely ...

A function called 'fn'
> void fn(){assert(0);}	// make a function
and an alias called 'fn'
> alias gm fn;		// alias the second with the name of the first

I would have thought that something along the lines of ...

  test.d(6): alias test.fn conflicts with test.fn at test.d(1)

would be a lot more useful.
-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
16/05/2006 11:06:23 AM
May 16, 2006
In article <sbwzwiubkkgj.wwgyourrqvs4.dlg@40tude.net>, Derek Parnell says...
>
>On Mon, 15 May 2006 15:22:59 -0700, BCS wrote:
>
>> Is this proper operation?
>> 
>> -------------
>> void fn(){assert(0);}	// make a function
>> void gm(){assert(0);}	// make another function
>> alias gm fn;		// alias the second with the name of the first
>> void main()
>> {			// make pointer-to-function from name
>> 	void function() fnp = & fn;
>> 			// call pointer-to-function
>> 	fnp();
>> 	// fn();	// wont compile with this line included
>> }
>> -------------
>> 
>
>I think it should be a compile error. However the error that is shown is really weird!
>
>  test.d(13): function test.fn called with argument types:
>          ()
>  matches both:
>          test.fn()
>  and:
>          test.gm()
>

Thanks for the sanity check, I didn't think I was missing anything but it's always nice to get a second opinion.

as to the error message I think that what is happening is that the "things" that the string "fn" can be referring to are printed. Line numbers would be really helpful