What this C++ constructor-elision question tests
This is a hard language-knowledge question that probes your understanding of copy and move semantics in C++14, and specifically how compiler optimizations affect object lifetime and constructor invocation. It requires detailed knowledge of the C++ standard and non-obvious behavior that differs across compilation flags.
The question asks you to trace through code execution when a common optimization is explicitly disabled. This tests whether you can reason about the difference between what the standard permits (elision) and what actually happens when that optimization is turned off. You need to understand constructor calls, temporary object lifetimes, and the order in which constructors and destructors fire—knowledge that separates candidates who have studied the language deeply from those who rely on intuition or typical compiler behavior.
- Return value optimization (RVO) and named return value optimization (NRVO)
- Move semantics and move constructors
- Temporary object lifetimes and the sequence of constructor/destructor calls
- How compiler flags affect standard-compliant behavior