Are function template parameters T& and T&& ambiguous?

116 views Asked by At

Consider these two overloads:

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

Are they potentially ambiguous?

The following code compiles with Clang 3.4, but fails with GCC 4.8, which says the overloads (first one with T = int, second one with T = int&) are ambiguous.

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

I realize that "binding to a reference" is an "exact match" in terms of overload resolution, so I imagine that the question boils down to whether one of the deductions T = int/T = int& is preferable over the other, or if they're equally good.

0

There are 0 answers