Skip to content

Instantly share code, notes, and snippets.

Guaranteed copy elision for named return values

This proposal aims to provide guaranteed copy elision for common cases of local variables being returned from a function.

Motivation

The accepted P0135 proposal already provides guaranteed copy elision for when a prvalue is returned from a function by stating that the result object of that prvalue (and not a temporary) is directly copy-initialized. It de-facto mandates what was known as Return Value Optimization (RVO) and allows non-movable objects to be returned in such a way.

Meanwhile, other cases of copy elision are still optional. For example, sometimes we want to create an object, set it up and return it.