Inconsistent overload resolution using rvalue references

My understanding of overload resolution is that "T & &" is usually better than "const T &". However, I see some inconsistent behavior among compilers with this trivial example:

#include <iostream>

void Func(const double& a)
{
    (void)a;
    std::cout << "[lvalue]\n";
}

void Func(double&& a)
{
    (void)a;
    std::cout << "[rvalue]\n";
}

template <typename T>
void TFunc(T&& a)
{
    Func(a);
}

int main ()
{
    TFunc(5.5f);

    return 0;
}

Clang 3.2 will print [rvalue] . However, VS2013 32 bit / 64 bit compilers will print [lvalue] . If I changed “5.5f” to “5.5”, then both compilers will print [lvalue] .

, VS 'const double &' std:: forward '& &' . , , , "& &" - .

float clang? ?

+4
1

5.5f, T float, Func Func(double(a)). , rvalue.

5.5, T , Func(a) . rvalue, lvalue.

MSVC , lvalue. lvalue . /Za ( ) - , clang.

+7

All Articles