Problem with overloading template functions
Sean Kelly
sean at f4.ca
Fri Sep 21 20:55:12 PDT 2007
This appears to be a bug in the overloading mechanism, but it's a
borderline case so I wanted to ask before submitting a ticket. Given
the following code:
void proc(T)( T val )
{
printf( "proc:T\n" );
}
void proc(T,U=void)( T[] val )
{
printf( "proc:T[]\n" );
}
void main()
{
proc( 0 );
proc( "abc".dup );
}
I would expect to see:
proc:T
proc:T[]
Because proc:T[] is more specialized and thus should be preferred for
the second call. Instead, it prints:
proc:T
proc:T[]
Interestingly, moving the dummy parameter to the first function:
void proc(T,U=void)( T val )
{
printf( "proc:T\n" );
}
void proc(T)( T[] val )
{
printf( "proc:T[]\n" );
}
void main()
{
proc( 0 );
proc( "abc".dup );
}
Results in the expected behavior:
proc:T
proc:T[]
I can only assume this means that the dummy parameters required to
support overloading are considered for determining how specialized a
particular function is, even though they are not used in the function
parameter list. Can someone please confirm that this is a bug and not
intended behavior?
Sean
More information about the Digitalmars-d-bugs
mailing list