The following program prints T,T
.
#include <iostream>
template<typename T>
void f(T x, T y) {
std::cout << "T,T\n";
}
template<typename T1, typename T2>
void f(T1 x, T2 y) {
std::cout << "T1,T2\n";
}
int main() {
f(1, 1);
return 0;
}
It makes no difference which template comes first in the code.
I would expect overload resolution to be ambiguous here. T
, T1
, and T2
should all be deduced as int
, which makes both templates match the call site exactly.
I haven't been able to find any resolution rules (https://en.cppreference.com/w/cpp/language/overload_resolution) to explain why it would choose the first template.
I tested with clang++ -std=c++17
, in case that matters.
T
,T
) are favored over different ones (T1
,T2
) as a tiebreaker.