possible bug with function pointers and aliases

Derek Parnell derek at psych.ward
Mon May 15 18:16:07 PDT 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



More information about the Digitalmars-d-bugs mailing list