Is this undefined behavior? If not, what is the behavior?
// In some external library with, say, header "a.h" void f(int &&x) { x = 5; // Which memory does this assignment apply to? } #include "a.h" int main() { f(7); // At this point, where is the value of 5? return 0; }
x = 5go to?f, a temporary of is created with value7, exactly as if we wrotef(const int& x), only this is notconst.xrefers to this temporary, and since it's notconst, we can change it. However, this is only a local variable so outsidef(), this value is lost.f(int),f(int&), orf(const int&).