http://d.puremagic.com/issues/show_bug.cgi?id=1528
--- Comment #26 from Kenji Hara <[email protected]> 2013-03-14 09:01:49 PDT --- (In reply to comment #24) > (In reply to comment #23) > > I think this rule is problematic for the function vs. deduced parameter case. > > // vs deduced parameter > int f3(int a) { return 1; } > int f3(T)(T b) { return 2; } > f3(1L); > > With first overload version, > Phase 1: normal function is treated as having empty template parameter list, > so > matching is always exact ==> MATCHexact > Phase 2: int <- 1L == MATCHconvert ==> MATCHconvert > > With second overload version, > Phase 1: T <- typeof(1L) = long ==> MATCHconvert > Phase 2: T <- 1L == MATCHexact ==> MATCHexact > > - the current implementation in the pull request chooses > the function whereas comment #13 and #16 suggest to go > with the function template > > https://github.com/9rnsr/dmd/blob/b141e29e29b1ec43873c7e0374d27d3fbbae8085/test/runnable/overload.d#L216 > https://github.com/9rnsr/dmd/blob/b141e29e29b1ec43873c7e0374d27d3fbbae8085/test/runnable/overload.d#L279 > > - C++ chooses the function template > > - For me it's counterintuitive to call with conversion when an exact > match can be instantiated. Even an ambiguous error seems more reasonable to > me. Right now I think that was little bad example. Ques. Why f3(1L) chooses non-template version? Short Ans. Because the given argument 1L is a literal. Long Ans. In D, literals works as like polysemous value. 1L is implicitly convertible to int by Value Range Propagation, so it matchs with MATCHconvert. If you give a runtime long value to f3: long n; f3(n); With first overload version, Phase 1: normal function is treated as having empty template parameter list, so matching is always exact ==> MATCHexact Phase 2: int <- n == MATCHnomatch (changed!!) With second overload version, Phase 1: T <- typeof(1L) = long ==> MATCHconvert Phase 2: T <- 1L == MATCHexact ==> MATCHexact So it will choose template version. How about? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
