Bug 617 – IFTI doesn't use normal promotion rules for non-template parameters

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2006-11-28T09:52:00Z
Last change time
2014-02-15T13:19:21Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
wbaxter
Blocks
1856

Comments

Comment #0 by wbaxter — 2006-11-28T09:52:40Z
For regular function matching, an int argument can be automatically converted to a size_t. But if IFTI is in play, then the difference between int and size_t in the function's parameter list causes IFTI to fail to find a match. ------- import std.stdio : writefln; void simple_func(char[] s, size_t i) { writefln(s, i); } void simple_func_t(T)(T s, size_t i) { writefln(s, i); } void main(char[][] args) { // ok as basic function simple_func(args[0], 3); // ok with explicit type simple_func_t!(char[])(args[0], 3); // ok with exact match on non-template param simple_func_t!(char[])(args[0], 3u); // Fails to to match with IFTI: // "template template_deduction.simple_func_t(T) does not // match any template declaration // template template_deduction.simple_func_t(T) cannot // deduce template function from argument types (char[],int)" simple_func_t(args[0], 3); }
Comment #1 by thomas-dloop — 2006-11-29T15:36:27Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb am 2006-11-28: > http://d.puremagic.com/issues/show_bug.cgi?id=617 > For regular function matching, an int argument can be automatically converted > to a size_t. But if IFTI is in play, then the difference between int and > size_t in the function's parameter list causes IFTI to fail to find a match. > > ------- > import std.stdio : writefln; > > void simple_func(char[] s, size_t i) > { > writefln(s, i); > } > void simple_func_t(T)(T s, size_t i) > { > writefln(s, i); > } > > > void main(char[][] args) > { > // ok as basic function > simple_func(args[0], 3); > > // ok with explicit type > simple_func_t!(char[])(args[0], 3); > > // ok with exact match on non-template param > simple_func_t!(char[])(args[0], 3u); > > // Fails to to match with IFTI: > // "template template_deduction.simple_func_t(T) does not > // match any template declaration > // template template_deduction.simple_func_t(T) cannot > // deduce template function from argument types (char[],int)" > simple_func_t(args[0], 3); > } Added to DStress as http://dstress.kuehne.cn/run/t/template_49_A.d http://dstress.kuehne.cn/run/t/template_49_B.d http://dstress.kuehne.cn/run/t/template_49_C.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFbf+NLK5blCcjpWoRAsoKAJ4k/a8BP67hinQp3+Ae82LZEuIQsgCeKqwZ /AJVkA45XnK8ddpPf1M0BPY= =4yoq -----END PGP SIGNATURE-----
Comment #2 by wbaxter — 2006-11-29T18:28:32Z
(In reply to comment #1) > > // ok with exact match on non-template param > > simple_func_t!(char[])(args[0], 3u); > Added to DStress as > http://dstress.kuehne.cn/run/t/template_49_A.d > http://dstress.kuehne.cn/run/t/template_49_B.d > http://dstress.kuehne.cn/run/t/template_49_C.d > Oops the line above is supposed to be *without* the explicit template arg: // ok with exact match on non-template param simple_func_t(args[0], 3u); But it doesn't look like that will affect your dstress tests.
Comment #3 by thomas-dloop — 2007-04-27T12:35:53Z
*** Bug 1178 has been marked as a duplicate of this bug. ***
Comment #4 by larsivar — 2008-01-22T16:47:39Z
Just noting that this bug (when propagated to GDC), means that code that should be portable to 64 bit targets isn't, and requires casts as a workaround. Examples include foo(cast(size_t)3) instead of foo(3u).
Comment #5 by bugzilla — 2008-07-09T22:37:10Z
Fixed dmd 1.032 and 2.016