Can compiler generate std::move for a last use of lvalue automatically?

前端 未结 3 1246
暖寄归人
暖寄归人 2020-11-29 11:51

A code like this is often seen in r-value references articles:

Dave Abrams: Move It With Rvalue References

void g(X);

void f()
{
    X b;
    g(b);          


        
3条回答
  •  广开言路
    2020-11-29 12:42

    (...) assuming a generic case the compiler does not know anything about how is move, copy or destruct implemented for the X class?

    No, compilers are not allowed to do optimisations based on faith.

    For clarity, this question is unrelated to copy elision: compilers may be allowed to elide a copy, but they cannot change copies to moves willy-nilly.

提交回复
热议问题