To Pass and Return — The Story of Functions, Values and Compilers
summary
Explains that C++17 makes copy elision mandated in C++17 for returned temporaries but real compilers differ: GCC/Clang eliminate copies for trivial and many complex cases, often inlining and creating return objects directly in caller storage; oversized objects use a caller-allocated buffer and pointers are passed in registers or on the stack. Intel (icc) and MSVC sometimes emit extra temporaries and perform one or two copy/move constructions — MSVC notably constructs a temporary and then copies it into the result in the shown examples — while GCC/Clang can even partially remove non‑trivial moves.
AI-written summary · about
chapters (12)
- 0:00Start
- 5:36Takeaways
- 10:47Oversized Object
- 14:07Returning by Value
- 19:58The Return Value Optimization
- 21:27Return Value Optimization
- 23:02Delay Temporary Materialization
- 25:31Random Condition
- 25:58Return Statements
- 28:10Msvcd
- 46:50Summary
- 47:28Answers
related talks
37mC++ Zero Overhead Pass by Value Through Invocable C++ Abstractions
50mC++ Costless Abstractions: the compiler view
58mC++17 in Practice - The good and the ugly
59mBack to Basics: Move Semantics
01h 04m“Understanding Optimizers: Helping the Compiler Help You”
01h 00mC++17, part 1: The Language Features
01h 00mType punning in modern C++
31mCo- and Contra-: Adding a Little Variance
