non-class rvalues always have cv-unqualified types

Posted by FredOverflow on Stack Overflow See other posts from Stack Overflow or by FredOverflow
Published on 2010-01-30T23:31:52Z Indexed on 2010/03/28 11:23 UTC
Read the original article Hit count: 420

Filed under:
|
|
|

§3.10 section 9 says "non-class rvalues always have cv-unqualified types". That made me wonder...

int foo()
{
    return 5;
}

const int bar()
{
    return 5;
}

void pass_int(int&& i)
{
    std::cout << "rvalue\n";
}

void pass_int(const int&& i)
{
    std::cout << "const rvalue\n";
}

int main()
{
    pass_int(foo()); // prints "rvalue"
    pass_int(bar()); // prints "const rvalue"
}

According to the standard, there is no such thing as a const rvalue for non-class types, yet bar() prefers to bind to const int&&. Is this a compiler bug?

EDIT: Apparently, this is also a const rvalue :)

© Stack Overflow or respective owner

Related posts about c++

Related posts about c++0x