I have TTempTable
class with move symantics. I wrote
TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}
and got no compiler errors.
Was this correct?
I have TTempTable
class with move symantics. I wrote
TTempTable&& MyFunction() {
TTempTable tmp = f(...);
...
return std::move(tmp);
}
and got no compiler errors.
Was this correct?
No, it is not correct.
You're returning a reference to a local variable. That reference is dangling.
Like any dangling thing, the compiler won't [always] diagnose it for you.
Return by value, and remove the std::move
(it's redundant and inhibits elision).
© 2022 - 2024 — McMap. All rights reserved.