3 ms·
The warning that I would want would trigger when someone changes the function and prevents or suppresses copy elision from happening. Like for example adding a
by daemin 7y ago
The warning that I would want would trigger when someone changes the function and prevents or suppresses copy elision from happening. Like for example adding a check at the start of the function and returning a default container.
- gpderetta 7y agomaking the returned object non copyable, non movable is a an option. edit: also, the rule is simple: RVO is always mandated, NRVO remains an optimization.
- daemin 7y agoI'm not sure if C++14 or C++17 has fixed this but if the object was not copy-constructible then the compiler would emit an error if it was returned by value even if RVO/NRVO was meant to be used. I figure because semantically you need to enable copy-construction of the object.
- gpderetta 7y agoIIRC it was changed in C++14. Now in the RVO case, no copy/move constructor is required (and in fact the compiler is not allowed to call it if it exists).