When `const auto& r = cond ? a : b;` Becomes a Dangling Reference – 3 C++ Lifetime‑Extension Pitfalls
The article explains that although C++ extends the lifetime of temporaries bound to a const reference, this rule has three critical edge cases—returning const references from functions, binding references in member initializer lists, and using the ternary operator—each of which can produce a dangling reference and cause obscure runtime crashes.
