Return Value Optimization: Harder Than It Looks
summary
Explains where the return slot lives in typical calling conventions, why C++03/C++11/C++17 rules sometimes elide, sometimes move, and sometimes silently copy; shows surprising failures: slicing and base-class converting constructors block the implicit move, conversion operators and by-value sinks cause copies, rvalue-reference parameters behave differently; implements a Clang diagnostic (-Wreturn-std-move) that detects problematic return x cases and suggests fixes.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 0:45The Return Slot
- 1:50Big Objects
- 3:08Moving Objects
- 4:45Copy Elision
- 6:34durian
- 7:42RPO rules
- 9:43Example
- 12:28The real deal
- 16:25Why converting constructors
- 18:29Examples
related talks
54mBack to Basics: Move Semantics (part 2 of 2)
05mCopy Elision
58mTo Move or Not to Move - An Interactive Analysis
55mBack to Basics: Move Semantics (part 1 of 2)
54mBack to Basics: Understanding Value Categories
01h 02mUnderstanding C++ Value Categories: lvalue, rvalue, xvalue, std::move, std::forward & Best Practices
01h 19mThis is C++: Uncompromised Performance, Undefined Behavior, & Move Semantics
01h 27mDangerous Optimizations! in C++ - Part Deux
