Title
Overload resolution between const T& and T&&
Status
nad
Section
13.10.3.2 [temp.deduct.call]
Submitter
Steve Adamczyk

Created on 2009-12-17.00:00:00 last changed 173 months ago

Messages

Date: 2010-08-15.00:00:00

Rationale (August, 2010):

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

Date: 2022-11-20.07:54:16

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;
        f(x);
    }

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 13.10.3.2 [temp.deduct.call] paragraph 3, T is deduced as const int&; application of the reference-collapsing rules in 9.3.4.3 [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.

History
Date User Action Args
2010-08-23 00:00:00adminsetmessages: + msg2957
2010-08-23 00:00:00adminsetstatus: open -> nad
2009-12-17 00:00:00admincreate