如何 return && 从函数对象?

How to return && object from function?

我有 TTempTable class 和移动语法。我写了

TTempTable&& MyFunction() {
   TTempTable tmp = f(...);
   ...
   return std::move(tmp);
}

没有编译器错误。

这是正确的吗?

不,这是不正确的。

你是returning a reference to a local variable。该引用悬而未决。

就像任何悬空的东西一样,编译器不会 [总是] 为您诊断它。

Return 按值,并删除 std::move (it's redundant and inhibits elision).