Bug 2699 – template functions doesn't specialize types of arguments correctly.

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-03-01T05:11:00Z
Last change time
2015-06-09T01:21:07Z
Assigned to
nobody
Creator
kk_tnr

Comments

Comment #0 by kk_tnr — 2009-03-01T05:11:31Z
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 by yebblies — 2012-02-19T23:36:25Z
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.