Why this is ambiguous?
template<class T> void g(T) {} // 1
template<class T> void g(T&) {} // 2
int main() {
int q;
g(q);
}
I understand that this is partial ordering context. And my, possibly erroneous, thinking is: any T& from #2 can be put in #1, but not any T from #1 is legit in #2. So partial ordering should work.
OK. I think this is what you’re looking for. Not diving into the twice-application of the parameter vs. argument type comparison, the following in the standard leaps out at me:
C++11 §14.8.2.4p6 goes on to talk about what happens when both are reference types, but that isn’t applicable here (though also an interesting read). in your case, only one is, so it is stripped. From there:
Now both are completely equal, and thus you have your ambiguity, which I believe is solidified from C++11 §14.8.2.4p10. The text of C++11 §14.8.2.4p9 covers both being reference types which, again, is not the case here:
But reading the standard in this section is like deciphering greek to me, so I may be way off base. (no offense to the Greeks =P).
It did, however, make me think "a
const T&against aT, given the same invoke conditiong(q), should also be ambiguous if everything I just read is enforced as-written." Sure enough, I tried it, and the same ambiguity was flagged.