www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Problem with overloading template functions

reply Sean Kelly <sean f4.ca> writes:
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
Sep 21 2007
parent Sean Kelly <sean f4.ca> writes:
Sean Kelly wrote:
 
 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[]
Er, I meant that it prints: proc:T proc:T Sean
Sep 21 2007