D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2699 - template functions doesn't specialize types of arguments correctly.
Summary: template functions doesn't specialize types of arguments correctly.
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-01 05:11 UTC by CLXX
Modified: 2015-06-09 01:21 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description CLXX 2009-03-01 05:11:31 UTC
DMD 2.205 on Windows

See this code.

import std.stdio: writefln;
void main( ){
    int a = 1;
    funcA( [a] );
    funcA!( typeof( [a] ))( [a] );
}
void funcA( T )( T t ){
    writefln( "funcA, T" );
}
void funcA( T: T[] )( T[] t ){
    writefln( "funcA, T: T[]" );
}

It is compiled with no errors.
Result:

funcA, T
funcA, T: T[]

This means, 'funcA( [a] );' is not equal to 'funcA!( typeof( [a] ))( [a] );'
Perhaps it is not a bug, but is not good spec.

Thank you for your reading.
Comment 1 yebblies 2012-02-19 23:36:25 UTC
The problem is here:

void funcA( T: T[] )( T[] t )

Calling with an int[] parameter infers T to be int, which does _not_ fit the specialization.

void funcA( T: U[], U )( T t )
works.