This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


1014. Overload resolution between const T& and T&&

Section:  []     Status: NAD     Submitter: Steve Adamczyk     Date: 2009-12-17

In the following example,

    template<typename T> void f(const T&);  // #1
    template<typename T> void f(T&&);       // #2
    void g() {
        const int x = 5;

the call f(x) is ambiguous by the current rules. For #1, T is deduced as int, giving

    f<int>(const int&)

For #2, because of the special case for T&& in [] paragraph 3, T is deduced as const int&; application of the reference-collapsing rules in [dcl.ref] paragraph 6 to the substituted parameter type yields

    f<const int&>(const int&)

These are indistinguishable in overload resolution, resulting in an ambiguity. It's not clear how this might be addressed.

Rationale (August, 2010):

The two functions are distinguished by partial ordering, so the call is not actually ambiguous.