[Issue 14802] Template argument deduction depends on order of arguments

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jul 16 07:22:33 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14802

--- Comment #2 from Ivan Timokhin <timokhin.iv at gmail.com> ---
(In reply to Steven Schveighoffer from comment #1)
> template deduction depends on "common type" deduction.
> 
> For two types that implicitly cast to each other, it has to make an
> arbitrary decision. Same thing happens with 1, 1U.
> 
> However, when it cannot implicitly convert one to the other, the decision is
> to use the one that both can accept. For example: 1, 1L yields the same type
> as 1L, 1.

Well, if this is expected and desired, then all right, but this is certainly
weird.

For one, I dont't think compiler should make arbitrary decisions on user's
behalf. It might just as well pick an arbitrary function from an overload set
if there are several equally good candidates, but it doesn't. Why does it do so
for types?

Furthermore, in both cases there seems to be one option that is better than the
other: for float and double the common type should definitely be double, as
more precise, for int and uint — probably uint, because int is promoted to uint
in arithmetic expressions, but not the other way around.

--


More information about the Digitalmars-d-bugs mailing list