What is Return Value Optimization (RVO) and Copy Elision?

Last updated 21 June 2026

  • Copy elision is a compiler optimization that builds an object directly in its final location, skipping copy/move constructions. RVO (Return Value Optimization) is the case of a returned object built straight into the caller's storage.

  • Since C++17, returning a prvalue temporary is guaranteed elided (works even with deleted copy/move constructors). NRVO (eliding a named local) is allowed but not guaranteed.

  • Don't write return std::move(local): it disables NRVO and forces a move.

  • https://www.geeksforgeeks.org/cpp/copy-elision-in-cpp/
  • https://en.wikipedia.org/wiki/Copy_elision
All C++ interview questions