Are the template parameters of the T & and T && functions ambiguous?

Consider these two overloads:

template <typename T> void foo(T &) {} template <typename T> void foo(T &&) {} 

Are they potentially ambiguous?

The following code compiles using Clang 3.4, but does not work with GCC 4.8, which says that overloads (the first with T = int , the second with T = int& ) are ambiguous.

 int main() { int n = 10; foo(n); } 

I understand that “link binding” is an “exact match” in terms of overload resolution, so I think the question boils down to whether one of the deductions T = int / T = int& is preferable over the other, or if they equally good.

+6
source share

All Articles