I'm confused by the following code:
struct test {
void f() & {
std::cout << "&" << std::endl;
}
void f() const& {
std::cout << "const&" << std::endl;
}
void f() && {
std::cout << "&&" << std::endl;
}
void f() const&& {
std::cout << "const&&" << std::endl;
}
void g() & {
std::cout << "& -> ";
f();
}
void g() const& {
std::cout << "const& -> " ;
f();
}
void g() && {
std::cout << "&& -> ";
f();
}
void g() const&& {
std::cout << "const&& -> ";
f();
}
test() {} //allow default const construction
};
int main(int, char**) {
test value;
const test constant;
value.g();
constant.g();
std::move(value).g();
std::move(constant).g();
}
When I compile with clang 3.5 I get this output:
& -> &
const& -> const&
&& -> &
const&& -> const&
Why is the r-value qualifier being dropped here? And is there any way to call f
from g
with the right qualifier?